Jump to content

Show Images Stored In Database


kelleydl

Recommended Posts

I have a database which stores user profile images. profile.php is the page that shows the image which calls image.php. image.php has the code involved in contacting the database and pulling information from it. when i run the page it shows a broken image eventhough i DO have an image in the database for it. the code i have for each is below.profile.php ~<img src="image.php?pid=1"> <!-- pid=1 grabs the user with id 1 -->image.php ~<?php $id = $_REQUEST['pid']; include("connectdb.php");$result = mysql_query("SELECT * FROM profiles WHERE groupID='$id'");while($row = mysql_fetch_array($result)){ $image = $row["groupPhoto"]; //group photo which is the name of the column in the database header("Content-type: $type"); header("Content-length: $size"); print $image;}?>

Link to comment
Share on other sites

Pull up the image URL directly to see if there's an error there. If PHP outputs an error you'll see that as a broken image. Why do you have a loop in your code? If your code tries to output more than one image it's going to break the data. There's no reason to use a loop there. It also looks like you're trying to use $type and $size without setting them.

Link to comment
Share on other sites

Pull up the image URL directly to see if there's an error there. If PHP outputs an error you'll see that as a broken image. Why do you have a loop in your code? If your code tries to output more than one image it's going to break the data. There's no reason to use a loop there. It also looks like you're trying to use $type and $size without setting them.
I took out the loop and and $type and $size. Still didn't work, so I tried pulling it directly.You do mean typing the full URL to image.php in my browser right?!? I did that and it just brought up a bunch of encoding like this..?JFIFdd?Ducky`{???M@u?̿Pqq??ɳw ?Л쌥Ǝ锾?{Ƌ$/kˁ???<zΖ?mͮѸˆ;j?C$Ű?^׵??鴞d??ذ콙? ...etc.I don't know what else to try. Its set in my database as a mediumblob and I know it has plenty of memory space. And when I pull it up from profile.php using <img src="image.php?pid=1"> it just shows the broken image, square with an X inside. Thanks a lot
Link to comment
Share on other sites

I didn't really mean to remove the type and size, I just meant fix it so it uses the correct type and size. You still need a content-type header to tell the browser what type of file to expect. Having a content-length header is useful to show the user a progress bar if they're downloading a file.

Link to comment
Share on other sites

Its still not working. Getting the same computer jibberish. I've tried using different coding such as 64byte_decoding and other things and its just not working. Its obviously retrieving the image information since its filling the page with symbols, but for some reason its not reading that it should be an image. I did put

header("Content-type: image/jpeg");

and I made sure the file is a jpeg file. Very frustrating for me, because I've been able to figure out and understand everything else, just not viewing an image from database.

Link to comment
Share on other sites

That should work, make sure you don't have any other output in the file, output no blank lines or spaces or anything other than the header and the binary image data. Make sure your include files aren't outputting anything either. There should be no blank lines before or after the PHP tags.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...