Re: Broken Links

From: Date: Wed, 23 Oct 2002 09:31:53 +0000
Subject: Re: Broken Links
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-121046@lists.php.net to get a copy of this message
Rankin, Randy wrote:
I am attempting to grab an image from a MySQL table and echo it back to a browser like so: <img border="1" src="./get_photo.php?image_id=<? echo $image_id; ?>"> However, All I get is broken links. I think I am just not understanding how all the Image functions need to line up. I do have GD compiled into PHP. I have pasted two get_photo.php versions below. The first one works, but does not create thumbnail images. The second one creates the broken images. I have been trying to get this to work for quite a while now, so any help would be appreciated. <----------------- Begin Code for WORKING NON-THUMBNAIL get_photo.php -----------------------------------> if( $image_id ) <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> { $sql = "SELECT image_bin_data, image_filetype from IMAGES where image_id=$image_id"; $result = db_query ( $sql ); $record = db_fetch_object ( $result ); $type = $record->image_filetype; $image = $record->image_bin_data; Header( "Content-type: $type"); echo $image; }; <----------------- End Code for WORKING NON-THUMBNAIL get_photo.php -----------------------------------> <----------------- Begin Code for NON-WORKING THUMBNAIL get_photo.php -----------------------------------> <? include ( "./includes/common/common.php" ); if( $image_id ) { $sql="SELECT image_bin_data, image_filetype from IMAGES where image_id=$image_id"; quote out $image_id, or anybody could send you image_id=0;DROP+TABLE+images and magic qoutes won't save you!
$result=db_query ( $sql ); $record=db_fetch_object ( $result ); $type=$record->image_filetype; $image=$record->image_bin_data; $new_w=75; $new_h=75; Header("Content-type: $type"); You transform the image to another type, so this should be static
$dst_img=ImageCreate($new_w, $new_h); $src_img=ImageCreateFromGif($image); ImageCreateFromGif expects a filename, use ImageCreateFromString instead
ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),I mageSY($src_img)); imageGif($dst_img); imageGif outputs the image to the browser, so the following line is redundant, also check if your gd library supports gif, else use png,
and fix header("Content-type: ") accordingly
echo $src_img; imagedestroy($dst_img); imagedestroy($src_img); } ?> <----------------- End Code for NON-WORKING THUMBNAIL get_photo.php ----------------------------------->


« previous php.general (#121046) next »