Re: Display an image through PHP

From: Date: Tue, 13 May 2003 04:50:45 +0000
Subject: Re: Display an image through PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147395@lists.php.net to get a copy of this message
Header( "Content-type: ".picture[1]); echo $picture[0]; The above code is all I use. What I ran into before was that I had the datatype too small in the database, so I would get a broken image. Make sure you have the data column atleast as a Blob (that's for upto 64 Kb images), and bigger blobs will give you more (medium blob is 16MB) Also when you store the image I use this (notice the use of mysql_escape_string): $image_tmp_name = $image ['tmp_name']; $image_data = mysql_escape_string(fread(fopen($image_tmp_name, "r"), filesize($image_tmp_name))); Hope that helps "Greg Beaver" <greg@chiaraquartet.net> wrote in message news:3EC073B4.3000001@chiaraquartet.net... > Hi, > > I'm trying to display an image dynamically, by extracting it from a > database. I've read the user-contributed notes at php.net for the > header() command, and also experimented with using the headers returned > from a direct look at a real .jpg and came up with this code: > > $picture = mysql_fetch_row($res); > header('Accept-Range: bytes'); > header('Content-Length: '.strlen($picture[0])); > header('Content-Type: '.$picture[1]); > header('Content-Disposition: inline; filename=file.jpg'); > echo $picture[0]; > > Assume that $picture is an array, [0] is the image data, and [1] is the > mime type (in other words, assume valid inputs) > > Using this code, I get a broken image. > > Anyone with header experience know how to trick the browser into > displaying the stupid picture? > > Thanks, > Greg >

« previous php.general (#147395) next »