Web Analytics Made Easy -
StatCounter Problem displaying Thumbnails from php file attached to html img tag - CodingForum


No announcement yet.

Problem displaying Thumbnails from php file attached to html img tag

  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem displaying Thumbnails from php file attached to html img tag

    I am using a php file to display JPG thumbnail images that I have saved in BLOB fields in a mySQL database table (using the phpthumb utility to convert them, FYI). The code itself is very straightforward:

    In the site php file (with the actual ID inserted instead of the code that builds it)…

    <img class="thumb" src="utils/simg.php?sid=66" /> (66 is the ID of the image in the image table, passed in as a variable)

    The simg.php file is also quite straightforward, the pertinent section shown here (without the code that builds the mySQL SELECT to get the image data):

    $imgresult = mysql_query($image);
    $image = mysql_fetch_array($imgresult);

    header("Content-type: $image[Type_e]");
    print $image[$size];

    The good news is that in my Live site that is up on the internet, it works perfectly, reading the data from the DB and displaying the image in the browser.

    However, I made a copy of the database for use in my “in development” site, exporting the image table from myPHPAdmin (with BLOB’s exported as HEX) and then importing the table into the new DB. When I use the copy of the database (using the same code with JUST the database switched), none of the images show up.

    To see what was going on, I exported the table from the original database and the copy database and looked at the hex of the BLOB’s side by side. They are identical when I look at the same image from each database as shown in the SQL export file. The first few bytes begin with FF D8 FF E0.

    When I run the site with the good DB and the bad DB, then inspect the frame and use Firefox to save the actual image data on my hard drive from each, I noticed the following puzzling differences between them:

    The good file starts with the Hex characters shown above (FF D8 FF E0), which is why it works.

    BUT…the bad file, which gives an error and displays nothing, has the following 6 bytes stuck at the beginning of the file: EF BB BF then the rest matches the good file (so, the first bunch are EF BB BF FF D8 FF E0).

    I have no idea what the extra bytes are, if it is some encoding thing or something about the database that is causing the image display function to add these characters. I am running the same exact code (not even a duplicate of the code) for both (I just changed the DB connection in my connect.php file and re-ran the site), but the output is not the same (the good one drawing the image and the bad one displaying nothing because of those extra bytes).

    I am not sure if this is a PHP problem, a SQL problem, an HTML problem or some encoding problem connected to the database itself. From everything I can tell, the entries in the same table in both databases is EXACTLY the same.

    Anyone out there with BLOB image experience know what might be going on? Hope I explained the situation clearly enough.

    Ben Cahan

  • #2
    Links to both images

    To be complete, the following are links to the image that works and the one that doesn't, in case anyone wants to see the hex of the file output for themselves:

    Good: http://www.talentville.com/utils/img.php?uid=66&s=2

    Bad: http://dev.talentville.com/utils/uimg.php?uid=66&s=2

    The bad one is from the copy of the code that I use to test new things, but I got the same result from original source code (the www site instead of the dev site). The dev version uses the new database, the www version uses the running site database, but the images are the same in both databases and the uimg source file is exactly the same.