Re: Writing a GIF/JPG Image

From: Date: Sun, 30 Jun 2002 21:54:04 +0000
Subject: Re: Writing a GIF/JPG Image
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-104759@lists.php.net to get a copy of this message
In article <20020628235711.65676.qmail@pb1.pair.com> , brando@augmented-chaos.com (Brandon) wrote: >I would like to store a jpg/gif image in a MySQL database (as a BLOB type I >guess ;p), how would I output that into an <img src=""> in php? You wouldn't, really. You would do something like this: <IMG SRC=fakeoutbrowser.php/image.gif?image_id=42 ...> Then, the PHP code in fakeoutbrowser.php would look like: <?php $query = "select imagedata from images where image_id = $image_id"; $image = mysql_query($query) or error_log(mysql_error()); # Check HTTP log for Errors! $image_data = @mysql_result($image, 0, 0); header("Content-type: image/gif"); echo $image_data; ?> NOTE: I *highly* recommend you *NOT* actually do this. Images will simply clog up your MySQL database, risk db-corruption, and slow down your MySQL data transfers to *NO* benefit. Unless you are the CIA doing high-end image-comparison in SQL to actually detect if two images "look alike" there's *NO* benefit to cramming your images into an SQL database. Far, far better to store them in a high-performance, customized, optimized, much-used data store commonly known as "the file system" :-) Just throw the images in a directory (possibly *outside* your web-tree) and use PHP/MySQL to authorize access, and even use PHP to http://php.net/fread the file, but not actually cram it into MySQL. -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#104759) next »