I want to display an image instead of loading it (image in a database block)

I want to display an image instead of loading it.

I have an image in my database table, in a BLOB column.

This snippet loads the image, but I want to display it:

$query = "SELECT * FROM upload";
$result  = mysql_query($query);
$row = mysql_fetch_array($result);
$content =  $row['content'];
$size =  $row['size'];
$type =  $row['type'];
header("Content-length: $size");
header("Content-type: $type");

// The following headers make the image download, but I don't want it to
// download, I want to show the image. What should I do?
// header("Content-Disposition: attachment; filename=$name");

echo $content;
+3
source share
3 answers

if you want to use it more dynamically, make a script of your source code and name it like this:

<img src="image.php?imageid=$myImageID" />

and your script:

$myImageID = $_GET["myImageID"];
$query = "SELECT * FROM upload where id='"+$myImageID+"'";
$result  = mysql_query($query);
$row = mysql_fetch_array($result);
$content =  $row['content'];
$size =  $row['size'];
$type =  $row['type'];
header("Content-length: $size");
header("Content-type: $type");
//header("Content-Disposition: attachment; filename=$name");---> this headers make system to download , but i dont want to download, i want to show image, what  should i do ,
echo $content; ?>"
0
source

The opposite arrangement of content attachmentis equal inline. Try the following:

header("Content-Disposition: inline; filename=$name");
+2
source

, , , . , exit echo $content; , , , .

0

Source: https://habr.com/ru/post/1772891/


All Articles