This is a discussion on image and databases problems within the alt.comp.lang.php forums, part of the PHP Programming Forums category; OK, sorry for those who answered my first post, but i have decided to store images in databases instead of ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
OK, sorry for those who answered my first post, but i have decided to store
images in databases instead of as files on the server. The problem i have is when i do a <img src="HTML/image.php?id=<?php echo $row['id']; ?>"> , it does not show an image, just a small empty area, CODE>> adding to a database $imgFull = imagecopyresized($newImg,$img,0,0,0,0,$fullWidth,$ fullHeight,$currentWidth,$currentHeight) ; $imgSQL = "INSERT INTO images (id,image,width,height,image_type) VALUES ('$id' ,'{$newImg}', '$fullWidth' , '$fullHeight' ,'".$_SESSION["IMAGE_TYPE"]."') "; CODE>> retrieving from database $sql = "Select * from images where (id = '$id')"; $results = mysql_query($sql, $conn); $row = mysql_fetch_array($results); $image_type = $row["image_type"]; $image = $row["image"]; Header ("Content-type: ".$image_type); echo $image; mysql_close($conn); if i just request the url (not embedded in a table and other HTML,) and comment out the header function i get "Resource id #4" instead of all the binary data i expected. I read that this was because this was a reference, not the image Thanks in advance if you need any extra info, just ask Jon |
|
|||
|
On Tue, 22 Jul 2003 19:56:48 +0100, Jon <jonchalk@hotmail.spam> wrote:
>OK, sorry for those who answered my first post, but i have decided to store >images in databases instead of as files on the server. >The problem i have is when i do a <img src="HTML/image.php?id=<?php echo >$row['id']; ?>"> >, it does not show an image, just a small empty area, > CODE>> adding to a database >$imgFull = >imagecopyresized($newImg,$img,0,0,0,0,$fullWidth, $fullHeight,$currentWidth,$currentHeight); I'm assuming that all your variables are correctly defined, since there's no information on them in this post. >$imgSQL = "INSERT INTO images (id,image,width,height,image_type) VALUES >('$id' ,'{$newImg}', '$fullWidth' , '$fullHeight' >,'".$_SESSION["IMAGE_TYPE"]."') "; That's not going to work... you've stored the image resource handle, not the data representing the image. And even if you had, you _absolutely need_ to run it through an escaping function, e.g. mysql_escape_string. http://uk.php.net/mysql_escape_string There's no information here as to how you execute the query (if at all), or whether you check for errors. >CODE>> retrieving from database >$sql = "Select * from images where (id = '$id')"; The brackets are superfluous. >$results = mysql_query($sql, $conn); You must check for errors. Do not ignore whether the return value is FALSE. >$row = mysql_fetch_array($results); >$image_type = $row["image_type"]; >$image = $row["image"]; >Header ("Content-type: ".$image_type); >echo $image; >mysql_close($conn); > >if i just request the url (not embedded in a table and other HTML,) and >comment out the header function i get "Resource id #4" instead of all the >binary data i expected. I read that this was because this was a reference, >not the image Yes - this is because you originally stored the image resource handle, NOT the image data that it refers to. Use imagepng, imagejpeg or whatever, and either write to a temporary file and read it back in again for the data, or capture the output with the output control functions. Then escape that data, and store that in the database. -- Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk) Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space) |
![]() |
| Thread Tools | |
| Display Modes | |
|
|