Jump to content

How to display a picture from a database


Fenhopi

Recommended Posts

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

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>";

 

?>

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!

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.