Results 1 to 7 of 7

Thread: PHP display image from database.

  1. #1

    PHP display image from database.

    I was looking at this thread: http://www.photoshopcafe.com/cafe/vi....php?tid=47918

    This seems to be what I need. The uploading part works great. But displaying the image is not. I pretty sure I have configured it the way I need it to be but I'm not sure why it's not working. Here is my code for the download page:

    Code:
    <?php
    if (! @mysql_connect("mysql","xxxxx","xxxxx")) {
            $errmsg = "Cannot connect to database";
            }
    @mysql_select_db("inventory");
    
    if(isset($_GET['id']))
    {
    // if id is set then get the file with the id from database
    
    include 'config.php';
    include 'opendb.php';
    
    $id = $_GET['id'];
    $query = "SELECT name, type, size, content " .
    "FROM main WHERE id = '$id'";
    
    $result = mysql_query($query) or die('Error, query failed');
    list($name, $type, $size, $content) = mysql_fetch_array($result);
    
    header("Content-length: $size");
    header("Content-type: $type");
    header("Content-Disposition: attachment; filename=$name");
    echo $content;
    
    include 'closedb.php';
    exit;
    }
    ?>
    And I'm using this to display the image on the page I want.

    <img src="download.php?id=1" border="0" alt="" />

    Thanks in advance!

  2. #2
    Programming Ninja mkeefe's Avatar
    Join Date
    Feb 2003
    Location
    Boston
    Posts
    7,794
    Have you verified that the image data is stored in the database or is it in the filesystem?

    Matt

  3. #3
    It appears that the picture is being stored in the database. I can't find it in the file system. I understand that storing files in the database isn't a good idea, but this will not be used a lot. There will only be about 2 pictures stored at a time.

    Thanks,
    Lance

  4. #4
    One problem I might have with this is that I do not have the config.php and opendb.php pages. And I do not know what's supposed to be in them.

  5. #5
    Programming Ninja mkeefe's Avatar
    Join Date
    Feb 2003
    Location
    Boston
    Posts
    7,794
    Originally posted by outatime
    One problem I might have with this is that I do not have the config.php and opendb.php pages. And I do not know what's supposed to be in them.
    That is likely the issue, those contain database connection information and urls, normally.

    Matt

  6. #6
    I have the connection information and the database select in the script itself. So do I still need these? And like I said: the uploading works fine without having the config and opendb pages. Sorry I am just really lost on this one.

  7. #7

    Hi,

    The botheration actuality is that you are alone able to use the agreeable disposition to forward out one file. pass4sure JN0-360 As anniversary balloon food a altered angel you will charge addition page thats loops through the DB, pass4sure 1Y0-A15 and displays the agreeable disposition page. you accept already told me how to affectation the images and its' agnate titles. pass4sure 1z0-050 I am now aggravating to accomplish the image's appellation to be a hotlink for the image's features.

Posting Permissions

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