Jump to content

Image display from Mysql issue


gnrmatt

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/235796-image-display-from-mysql-issue/
Share on other sites

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.

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.