#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Image download from database


    Hi,
    i know an image should not be stored in a db, just the link, but I just want to test it and it should work.

    Using phpmyadmin i have checked that image was successfully uploaded. But if i use my script, it is not displayed.

    PHP Code:
    ...
    $sqlS "SELECT upl_file, upl_type FROM ".$tab;  
    $sqlS.=" WHERE ID = '".mysql_real_escape_string($_GET['ID'])."'";  
    $result=@mysql_query($sqlS$link);  
    if(
    mysql_num_rows($result)==1)  
    {   
    $data mysql_result($result,00);   
    $typ mysql_result($result,01);   
    $kopf="Content-type: ".$typ;   
    header($kopf);   
    echo 
    $data;  
    }   
    else  
    {   
    die(
    '<h1>Download failed!</h1>');  

    same effect, if i try to download the image via html

    Code:
    ...
    <div align="center">  
    </h2>Display image from database</h2>  
    <img src="download_read.php?ID=6">  
    </div>
    ...
    other mime types can be downloaded, but image is never displayed with my script, just get a little icon "image" displayed.

    What do i have to do to download an image successfully?
    Thank you in advance for your support.
  2. #2
  3. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,119
    Rep Power
    1990
    You need to do a little more debugging.

    Remove the header() call from your script and call the image scripts URL directly, and you'll be able to see any error messages that are shown (oh, be sure that you have error reporting turned on as high as you can). That way you'll see the errors that are happening and you'll be able to fix them.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by Catacaustic
    You need to do a little more debugging.

    Remove the header() call from your script and call the image scripts URL directly, and you'll be able to see any error messages that are shown (oh, be sure that you have error reporting turned on as high as you can). That way you'll see the errors that are happening and you'll be able to fix them.
    Hi,
    thank you for your quick help.

    The mistake was the following, not viewable for you, because I thought it was not necessary to list the code

    PHP Code:
    #echo __FILE__;  
    #echo "<hr>"; 
    without comment sign the image is not displayed, now it works!

IMN logo majestic logo threadwatch logo seochat tools logo