gnrmatt Posted May 7, 2011 Share Posted May 7, 2011 Hi, I am having an issue with displaying an image that is uploaded in a mysql database. The table format is ----------------------------------------------------------- | id | name | mime | size | data | ----------------------------------------------------------- | 1 | test | image/jpeg| 74857 | BLOB | The data has uploaded fine. I then have the following script on my 'displayimage.php?imgid=1' page... $id = $_GET['imgid']; $result = mysql_query("SELECT * FROM images WHERE id = '$id'"); while($row = mysql_fetch_array($result)) $size = $row['size']; $mime = $row['mime']; $name = $row['name']; { header("Content-length: $size"); header("Content-type: $mime"); header("Content-Disposition: attachment; filename=$name"); echo $row['data']; However everytime i try to open this page, Firefox or Internet Explorer just ask's me to try and download the file as a php file. Any ideas what is going wrong? Thanks! Matt Quote Link to comment https://forums.phpfreaks.com/topic/235796-image-display-from-mysql-issue/ Share on other sites More sharing options...
fugix Posted May 7, 2011 Share Posted May 7, 2011 im assuming you have a server that this script is on? Quote Link to comment https://forums.phpfreaks.com/topic/235796-image-display-from-mysql-issue/#findComment-1212056 Share on other sites More sharing options...
gnrmatt Posted May 7, 2011 Author Share Posted May 7, 2011 Yes - Connection above: if(isset($_GET['imgid'])) // if id is set then get the file with the id from database $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); I tried removing the content-disposition header on guidance from a different thread but that also didnt work. Quote Link to comment https://forums.phpfreaks.com/topic/235796-image-display-from-mysql-issue/#findComment-1212057 Share on other sites More sharing options...
fugix Posted May 7, 2011 Share Posted May 7, 2011 im talking about a web server not a mysql server Quote Link to comment https://forums.phpfreaks.com/topic/235796-image-display-from-mysql-issue/#findComment-1212061 Share on other sites More sharing options...
gnrmatt Posted May 7, 2011 Author Share Posted May 7, 2011 Not to worry - Error has been resolved. For reference, I shouldn't have used while($row = mysql_fetch_array($result)) and instead used $row = mysql_fetch_assoc($result); Works a treat now. Quote Link to comment https://forums.phpfreaks.com/topic/235796-image-display-from-mysql-issue/#findComment-1212062 Share on other sites More sharing options...
fugix Posted May 7, 2011 Share Posted May 7, 2011 okay, i was asking that because if you dont have your php file in a web server directory, it triggers an error like that. glad your resolved the issue Quote Link to comment https://forums.phpfreaks.com/topic/235796-image-display-from-mysql-issue/#findComment-1212072 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.