Bb Way
Bb Way

Reputation: 59

saving an image from the browser issue

I'm using code to print an image without showing the real path for it. But I have a problem when I want to save that image to my computer because its always show the PHP file name as the name for the image.

$id = intval($_REQUEST["id"]);
$getimage = $db->query("select id,img from bbup where id='$id'");
$fetch_image = $db->fetch($getimage);
$filename = $fetch_image['img'];
if (!$id) {
    echo "Wrong Id";
    exit;
}
if (!file_exists($filename)) {
    echo "Image not found.";
    exit;
}
$aaa = SITE_URL . $filename;
$imginfo = getimagesize($aaa);
header("Content-type: " . $imginfo['mime']);
readfile($aaa);

The php file is ppupload.php and when I want to save the image (let's say it is a PNG image) in the dialog box the name of the file show ( ppupload.php.png ) and I want it to be the image itself.

The image path stored into the database like this: folder/folder/filename.ext.

Upvotes: 1

Views: 370

Answers (2)

Jay Pagnis
Jay Pagnis

Reputation: 1120

Have you tried setting the Content Disposition header?

header('Content-Disposition: attachment; filename='.$filename);
header('Content-Type: application/octet-stream');

This might help.

Upvotes: 2

sofl
sofl

Reputation: 1024

You can try to add something like this header("Content-Disposition: inline; filename=\"myimg.png\"");

Upvotes: 1

Related Questions