Reputation: 12920
I saved an image in MYSQL database as BLOB format. When I try to fetch that image, the web browser asks me to download it. I would ask how can I display the image directly in the browser.
The following is the code i used:
<?php
//$id = $_GET['id'];
include_once 'D_B.php';// Connect to server and select database.
$query = "SELECT `name`, `type`, `size`, `content` FROM `upload` WHERE `id`='1'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) =mysql_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;
exit;
?>
Upvotes: 0
Views: 2286
Reputation: 13557
Remove the Content-Disposition header: header("Content-Disposition: attachment; filename=$name");
and it should work fine.
Upvotes: 2