icE1 Posted September 14, 2006 Share Posted September 14, 2006 Hi,I'm trying to retrieve an image that I stored in a mySQL database. I'm able to get the name, id but however unable to get the image to show up. The image shows up as:ótvwnY·ÌôMëÉØö,`âJ5œ››úõÐ׫hÚnÑ'«©”Œèè褤£üüüÎÎÎæ¶y‰ŽØ’æææN…QÔÔÔŠ™¼EÛúúúF¶üÊñ…u’;¹s§øÚÚÚòiVò“…–––q†nkÝÝÞQºººNm±°°°”jvdùèåááá{“Å6«õxf/W®‘¤Í¶¶¶ÚåøÑÑÑd—ø°¸ÈúârÎɹ½½¾êÑjòòòø¸sÈÈÈööö™‡vïïðMXnÅÅÅ=Âøøø¨†vNHÆ€€©©©ôôô‹SLñõýíí튋My code for image retrieve is as follow:[code]<html><head><title>Download File From MySQL</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><?phpinclude 'config.php';include 'opendb.php';$query = "SELECT id, name, content FROM upload";$result = mysql_query($query) or die('Error, query failed');if(mysql_num_rows($result) == 0){echo "Database is empty <br>";} else{while(list($id, $name, $content) = mysql_fetch_array($result)){?><?phpecho $name;echo $id;echo $content;?><?php }}include 'closedb.php';?></body></html><?phpif(isset($_GET['id'])) {// if id is set then get the file with the id from databaseinclude 'config.php';include 'opendb.php'; $id = $_GET['id'];$query = "SELECT name, type, size, content " . "FROM upload WHERE id = '$id'";$result = mysql_query($query) or die('Error, query failed');list($name, $type, $size, $content) = mysql_fetch_array($result);header("Content-length: $size");header("Content-type: $type");header("Content-Disposition: attachment; filename=$name");echo $content;include 'closedb.php'; exit;}?>[/code]Can anyone help me? What have I left out? Link to comment https://forums.phpfreaks.com/topic/20713-retrieve-images-from-mysql/ Share on other sites More sharing options...
eipihipl Posted September 14, 2006 Share Posted September 14, 2006 you've forgotten the content-type HTTP headerheader('content-type: image/jpeg');cheers Link to comment https://forums.phpfreaks.com/topic/20713-retrieve-images-from-mysql/#findComment-91746 Share on other sites More sharing options...
fenway Posted September 14, 2006 Share Posted September 14, 2006 If you made it into the second control path, you should be fine, from the looks of it. Link to comment https://forums.phpfreaks.com/topic/20713-retrieve-images-from-mysql/#findComment-91780 Share on other sites More sharing options...
icE1 Posted September 14, 2006 Author Share Posted September 14, 2006 [quote author=eipihipl link=topic=108011.msg434185#msg434185 date=1158242881]you've forgotten the content-type HTTP headerheader('content-type: image/jpeg');cheers[/quote]Sorry but which part of my code should I insert this code in? Link to comment https://forums.phpfreaks.com/topic/20713-retrieve-images-from-mysql/#findComment-91818 Share on other sites More sharing options...
fenway Posted September 14, 2006 Share Posted September 14, 2006 I'm still confused as to why you have the first part of that PHP script there at all. Link to comment https://forums.phpfreaks.com/topic/20713-retrieve-images-from-mysql/#findComment-91833 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.