Jump to content


Small Image Problem


  • You cannot reply to this topic
No replies to this topic

#1 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 12 November 2006 - 10:11 PM

Alright, I've had this problem before, and I can't quite remember how I fixed it. :)

Here's the thing.
I've entered images as binary data into my database, using chunk_split() and base64_encode(), then I pull the out of the database using a script and output it to the browser. Now what I can't figure out, is for some reason, this was working perfectly for a few days, now suddenly it doesn't. I get several different scenarios.
  • The script dies and says the image has errors
  • The pure code of the image shows (in binary still)
  • The page shows a complete blank, even in the source
  • The page shows blank with just the page's URL, and in the source shows the binary image <- Most common one lately
  • Or the page shows up in Dreamweaver (sends directly to HTML editor as if I downloaded the file) - in this case may have any combination of the above errors
This is the tutorial I used just to figure out how to get it all working.

Here is the latest model of the script.

<?php
require('config.php');
$image = (int)trim($_GET['img']);

$mysql->query("SELECT `image`, `image_type` FROM `user_images` WHERE `image_id`='$image' LIMIT 1");

$row = $mysql->fetch_array();

header("Content-type: {$row['image_type']}");
print $row['image'];
?>
$mysql is a class I wrote with all my commands, etc. The $mysql->fetch_array() automatically grabs the last query resource given to the class, so it does get the information correctly. I've used var_dump() and print_r() to verify the data is there, and it is.
I've went back and reviewed several tutorials dealing with this, even just simple outputing images, and I've delt with things like this before (except for pulling it out of a database). I can't figure it out. :S

Here's a link to the script in action, just so you can maybe see what it's doing.



Edit!
I fixed it! Lol.
Turns out I had to instigate an new instance of the MySQL class, seperate from the config file. I suspect having ob_start() and alot of session handling in the config file may be what caused some problems. :P

Edited by Demonslay, 12 November 2006 - 10:31 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users