| 
	
 | 
 Posted by Jim Michaels on 04/17/06 08:26 
"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message  
news:Df2dnciza_0aONzZnZ2dnUVZ_vidnZ2d@comcast.com... 
> Jim Michaels wrote: 
>> <?php 
>> include 'dbinc.php'; 
>> $result = mysql_query("SELECT image,mime_type FROM photos WHERE  
>> image_id=".intval($_GET['id']), $link) or die("MyErr:".mysql_error()); 
>> if ($row = mysql_fetch_assoc($result)) { 
>>  
>> $ext=array('image/jpeg'=>'jpg','image/gif'=>'gif','image/png'=>'png','image/x-png'=>'png'); 
>>     header("Expires: Mon, 26 Jul 2030 05:00:00 GMT"); 
>>     header("Content-Type: $row[mime_type]"); 
>>     header("Content-Disposition: inline;  
>> $_GET[id].".$ext[$row['mime_type']]); 
>>     echo "\r\n".stripslashes($row['image']); 
>> } 
>> mysql_free_result($result); 
>> ?> 
>> 
>> what am I doing wrong?  I don't get an image.  I've seen thumbnail stuff.  
>> I don't want a thumbnail (that code didn't work either for some reason). 
> 
> I have no idea what you did wrong.  What do you get?  What's in the  
> source? What's in the database row? 
 
found the problem.  stripslashes and the newlines turned out to be a bug. so 
echo "\r\n".stripslashes($row['image']); 
became 
echo $row['image']; 
 
and the problem I was having with error messages about headers already being  
sent came because dbinc.php had some blank lines after the ?> 
:-/ 
well, at least I found it. 
The Expires header isn't necessary.  I should probably take it out.  The ;  
filename after inline isn't necessary either. (maybe it make things easier  
for the cache, but I disabled the page cache via headers elsewhere) 
 
I found another method would be to use imagecreatefromstring() and that  
somehow you can detect the mime-type from that rather than storing it in the  
db, butyou also have the problem that if the image is hefty (1MB), that  
function will consume 16MB of RAM.  combined with the use of another common  
function, it would take a total of 32MB.  PHP would then die.  this function  
is a memory hog (why?).  Then you use imagejpeg(). 
 
I *thought* you were supposed to send a newline to signify end of headers  
before sending image data.  It seems I was wrong.  I got the right size  
image placeholder, but no image.  weird.  guess I'd have to look at the  
format to see why that is. (?)  maybe PHP does some of this for me  
automatically or something behind the scenes. 
From the command-line I discovered after I sent out headers, imagejpeg()  
secretly inserts \r\n into the image data.  I had to get out my editor to  
binary-delete the first 2 bytes for the image to come out right.  my old  
copy of TSE 2.8 is still good for a few things. :-)
 
  
Navigation:
[Reply to this message] 
 |