Click to See Complete Forum and Search --> : Saving PHP-generated image to mysql blob


nudave04
06-29-2006, 09:32 AM
Hi,

I'm trying to generate thumbnails for images I upload to my site and save them to a mysql database (I'd rather do this than create new files.) Unfortunately, most of the tutorials out there on saving to BLOB deal with files uploaded from the user, where the raw contents of the file can be gotten by file_get_contents().

So, I have a function to generate the thumbnail that ends with:
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

This creates a resource $image_p that contains my thumbnail.
I know that a few lines from now, I need to have the line

$sql = "UPDATE `photos` set `thumbnail` = '$content' WHERE `ID` = '$ID'";

My question is what code I need to get the content of $image_p saved as $content in appropriate form to be stored in a blob.

Thanks!

nudave04
06-29-2006, 10:19 AM
Apparently, the function I'm looking for is "stream_get_contents()", but this is in php 5, and my server is running php 4.

Any idea on an equivalent? I would prefer not to have the overhead of writing the stream to a file if this isn't necessary.

bokeh
06-29-2006, 10:58 AM
I upload to my site and save them to a mysql databaseWell if you uploaded them to the correct place, which is the file sytem, you wouldn't be having this trouble.

nudave04
06-29-2006, 11:20 AM
I think you misunderstood me. What I want to save to the mysql database is the thumbnail (generated by PHP), NOT the original uploaded file. I have no problems with putting the original file in the correct location.

For now, I have an ungainly (and high-overhead) solution of writing the thumbnail to a temporary file, then getting the contents of the file with file_get_contents. Do you know of a way to get the contents of the thumbnail as a stream (i.e. w/o writing it to a file...) in PHP 4?