+ Reply to Thread
Page 5 of 16
FirstFirst ... 3 4 5 6 7 15 ... LastLast
Results 41 to 50 of 158

Thread: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

  1. #41
    Newbie sanyal is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    5

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    thanx........for u r reply......... orjan

    but i could not get u .......
    to put the below script and call the fetch.php page.........as it will b feching images with respective 'id'......

    your code.........

    similar to this:
    PHP Code:

    Code:
    $query mysql_query("SELECT * FROM images")or die("Cannot exe----- select the database: ".mysql_error());
    while(
    $row mysql_fetch_array($query)){
        
    $id $row[id];
        echo 
    "<img src='fetch.php?id=$id'>";
        echo 
    $row[comment];

    i tryed it .........i am able to get only image icons.........but not the images in the web page

    here is my code
    all_imgs.php =======>from this page i am calling fetch.php

    Code:
    <?php
    header
    ('Content-type: image/jpeg'); // act as a jpeg file
        
    mysql_connect('localhost','root','')or die(mysql_error());
        @
    mysql_select_db('test')or die(mysql_error()); // use the ‘test’ database

        
    $query mysql_query("SELECT * FROM images")or die("Cannot exe----- select the database: ".mysql_error());
    while(
    $row mysql_fetch_array($query))
    {
        
    $id $row[id];
        echo 
    "<img src='fetch.php?id=$id'><br>";
        echo 
    $row[comment];
    }  
        
    ?>
    //===============================================
    and here is the
    code for fetch .php (.........your code)
    Code:
    <?
    if(isset($_GET['id']))
    {
    header('Content-type: image/jpeg'); // act as a jpeg file
        
    mysql_connect('localhost','root','')or die(mysql_error());
        @
    mysql_select_db('test')or die(mysql_error()); // use the ‘test’ database

        
    $query 'select * from images where id = $id';
        
    $result mysql_db_query('test',$query)or die(mysql_error());

        
    $row mysql_fetch_array($result);
        
    $img $row['img'];

        echo (
    $img);
        }
        else{echo 
    'id is not send';}
    ?>
    can u post the whoe code.........
    and how can i show the id,title,img .........all at one place from the img table
    which fields say as imagestable (id,title,img,description)

    thax in advance
    Last edited by Jaan; 12-21-2008 at 06:03 AM. Reason: Please use code tags when you're posting your codes!

  2. #42
    Moderator Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan's Avatar
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Age
    34
    Posts
    2,613
    Blog Entries
    7

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Too tired right now to post full codes. But no, it's not possible to do everything from one file.

    you need one php to show the pictures, and another one to create the html-page that includes the pictures.

    the php-file to show the pictures is in full shown in the first posting with the tutorial.
    the other php-file where you read out the surrounding data is built after how you want it. but in general, it's where you read out everything from the database but the picture itself.

  3. #43
    Newbie Talkabout is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    2

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    when i'm trying to show images, i got something like this:
    h t t p : / / img156.imageshack.us/my.php?image=imagerf8.jpg (remove spaces, i'm new here and not able to post links, but there is what i get)
    i really don't know what's the problem
    my code is:
    Code:
    <?php

    $username 
    "root";
    $password "mypassword";
    $host "localhost";
    $database "scientific";

    @
    mysql_connect($host$username$password) or die("Can not connect to database: ".mysql_error());

    @
    mysql_select_db($database) or die("Can not select the database: ".mysql_error());

    $id $_GET['id'];

    if(!isset(
    $id) || empty($id)){
    die(
    "Please select your image!");
    }else{

    $query mysql_query("SELECT * FROM article WHERE id='".$id."'");
    $row mysql_fetch_array($query);
    $content $row['photo'];

    header('Content-type: image/jpg');
    echo 
    $content;
    }
    ?>
    please help me
    Thanks

  4. #44
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,066
    Blog Entries
    9

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    You get that.. because I don't know why..
    This is wierd.. It should display this:
    Code:
    die("Please select your image!"); 
    Trill Hosting - Cheap SSL, Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us

    CodeCall Blog | CodeCall Wiki

  5. #45
    Newbie Talkabout is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    2

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Quote Originally Posted by Jaan View Post
    You get that.. because I don't know why..
    This is wierd.. It should display this:
    Code:
    die("Please select your image!"); 
    well.. i tried another way. so in this way image should be displayed.. but it doesn't! and i really don't know why
    here is the code:
    form.html
    Code:
    <head>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <
    title>add pic</title>
    </
    head>
    <
    body>
    <
    form action="insert.php" method="post" enctype="multipart/form-data" name="changer" >
    <
    input name1="MAX_FILE_SIZE" value="102400" type="hidden">
    <
    input name="image" accept="image/jpg" type="file">
    <
    input value="Submit" type="submit">
    </
    form>
    </
    body>
    </
    html
    insert.php

    Code:
    <?php 
    $username 
    "root";
    $password "mypassword";
    $host "localhost";
    $database "scientifc";

    // Make the connect to MySQL or die
    // and display an error.
    $link mysql_connect($host$username$password);
    if (!
    $link) {
        die(
    'Could not connect: ' mysql_error());
    }

    // Select your database
    mysql_select_db ($database);  


    // Make sure the user actually 
    // selected and uploaded a file
    if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

          
    // Temporary file name stored on the server
          
    $tmpName  $_FILES['image']['tmp_name'];  
           
          
    // Read the file 
          
    $fp      fopen($tmpName'r');
          
    $data fread($fpfilesize($tmpName));
          
    $data addslashes($data);
          
    fclose($fp);
          

          
    // Create the query and insert
          // into our database.
          
    $query "INSERT INTO article ";
          
    $query .= "(title,text,domain_id, photo,validat) VALUES ('sdfdsdfsds','ssdafdfg',3,'$data',1)";
          
    $results mysql_query($query$link);
          
          
    // Print results
          
    print "Thank you, your file has been uploaded.";
          
    }
    else {
       print 
    "No image selected/uploaded";
    }

    // Close our MySQL Link
    mysql_close($link);
    ?>
    and printimage.php

    Code:
    <?php
    $username 
    "root";
    $password "mypassword";
    $host "localhost";
    $database "scientific";

    @
    mysql_connect($host$username$password) or die("Can not connect to database: ".mysql_error());

    @
    mysql_select_db($database) or die("Can not select the database: ".mysql_error());

    //$id = $_GET['id'];


    $id 22// just a test id to see if it works!

    if(!isset($id) || empty($id)){
    die(
    "Please select your image!");
    }else{

    $query mysql_query("SELECT * FROM article WHERE id='".$id."'");
    $row mysql_fetch_array($query);
    $content $row['photo'];

    header('Content-type: image/jpeg');
    echo 
    $content;
    }
    ?>
    record with id 22 contains an image, in the column photo
    where the f... is the problem ?

  6. #46
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,066
    Blog Entries
    9

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Well.. Do you have a table called a "photo" ? or something.. I believe it don't get dat pic from the database, that's why it don't work..
    Trill Hosting - Cheap SSL, Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us

    CodeCall Blog | CodeCall Wiki

  7. #47
    Newbie namhungsw28 is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    1

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    thanks for your tutorial!

  8. #48
    Newbie jpresch is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    2

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    it just downloads the show.php to my HD automatically for me. But dude, I am totally new to php and creating databases as of well...... an hour ago. Got the database working and I can see there are several BLOBS that got created. I assume those are the images but not sure how to actually view them in the browser window.
    Last edited by jpresch; 01-23-2009 at 10:31 PM.

  9. #49
    Newbie jpresch is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    2

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    LOL....You actually have to display it in an html page....WORKS Perfect! Thanks you rock. good tut, if I can figure it out with no previous experience you did well my man.

  10. #50
    Newbie pkincses is an unknown quantity at this point
    Join Date
    Feb 2009
    Posts
    1

    Re: Tutorial: Storing Images in MySQL with PHP / Part II / Display your images

    Hi guys

    My problem is similar to what was mentioned before:image is displayed as a raw file...I tried to remove all the html info that were before and after the php tags but didn't do the trick.Here is the code, hope one of you might be able to help.Thanks in advance...

    Code:
    <?php

    echo "<p>Recent uploads</p>";
    // Connect to the database server
    $dbcnx = @mysql_connect('localhost''root''root');
    if (!
    $dbcnx) {
     exit(
    '<p>Unable to connect to the ' .
         
    'database server at this time.</p>');
    }


    // Select the pictures database
    if (!@mysql_select_db('pictures')) {
     exit(
    '<p>Unable to locate the Pictures ' .
         
    'database at this time.</p>');
    }



    // Request the id, title, img of files
    $result = @mysql_query('SELECT id, title, images FROM details');
     if (!
    $result) {
       exit(
    '<p>Error performing query: ' .
           
    mysql_error() . '</p>');
     } 

    // Display $result in a paragraph
     
    while ($row mysql_fetch_array($result)) {
       
    $id $row['id'];
       
    $title $row['title'];
       
    $img $row['images'];
       
       
    header('Content-type : image/jpg');
       echo 
    '<blockquote>' $id$title$img .'</blockquote>';
     } 
     
    ?>
    Last edited by Jaan; 02-02-2009 at 09:50 AM. Reason: Please use code tags when you're posting your codes!

+ Reply to Thread
Page 5 of 16
FirstFirst ... 3 4 5 6 7 15 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Tutorial: Storing Images in MySQL with PHP
    By Jordan in forum PHP Tutorials
    Replies: 43
    Last Post: 01-16-2010, 10:35 AM
  2. Tutorial: PHP to MySQL
    By Jordan in forum PHP Tutorials
    Replies: 20
    Last Post: 08-28-2009, 04:22 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts