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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.