Fenhopi Posted June 14, 2010 Share Posted June 14, 2010 So, I've managed to store a picture into a database. This happens to be a profile picture for the user. I know that I'll need the query to be: $query = mysql_query("SELECT * FROM tbl_images WHERE byuser='$id'"); But that's about it. Whenever I try and write up a code to display the picture I only get it displayed as a raw file, which isn't cool. I heard that I can't have any html codes when I display a picture, but if this is so how is it possible to view it in my users' profile page? All help appreciated!! Quote Link to comment https://forums.phpfreaks.com/topic/204710-how-to-display-a-picture-from-a-database/ Share on other sites More sharing options...
steveangelis Posted June 14, 2010 Share Posted June 14, 2010 Just do this: <img src="<?PHP echo FROMDB_URL; ?>"> Quote Link to comment https://forums.phpfreaks.com/topic/204710-how-to-display-a-picture-from-a-database/#findComment-1071740 Share on other sites More sharing options...
JackAtack Posted June 14, 2010 Share Posted June 14, 2010 one way is like this header('Content-Type: image/jpg'); $image=fpassthru($tag); another is like this foreach ($dbh->query($query) as $row) { $name = $row['name'] ; $image = $row['image_data'] ; header('Content-type: image/jpg'); header("Content-Disposition: attachment; filename=$name"); echo $image; } then call the php file as such <?php echo"<html>"; echo"<head>"; echo"<title>Untitled 1</title>"; echo"</head>"; echo"<body>"; $a='images.php'; echo"<table style=\"border: medium groove #800000; width: 100%\">"; echo"<tr>"; echo " <td style=\"border: thin ridge #800000; width: 100px\"><img src='$a/image.jpg' /></td>"; echo " <td style=\"border: thin ridge #800000; width: 100%\">Description of person</td>"; echo " <td style=\"border: thin ridge #800000; width: 100px\"><img src=images/Adobe_PDF.jpg /></td>"; echo " </tr>"; echo " </table>"; echo " </body>"; echo"</html>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/204710-how-to-display-a-picture-from-a-database/#findComment-1071741 Share on other sites More sharing options...
Fenhopi Posted June 14, 2010 Author Share Posted June 14, 2010 Okay, those are great ideas, thanks! I'm confident this will solve my issue regarding the raw file. However I also have a problem that it says that headers are already sent, so my: header('Content-type: image/jpg'); won't work. And that's sort of an essential part. Headers are already sent in a file i have included, and it has to be included, is there anyway I do something to get around this? Thanks for the reply guys! Quote Link to comment https://forums.phpfreaks.com/topic/204710-how-to-display-a-picture-from-a-database/#findComment-1071742 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.