简体   繁体   中英

Php Image save as dialog box

I wanted to open a save image dialog box when I click on an image. I managed to open the same but when saved, it does not save open saved image as the content of image is not saved somehow.

PHP code:

$imageName = $_GET['i'];
$imageName = $imageName . '-HR.jpg';
header ("Content-Type: application/download");
header ("Content-Disposition: attachment; filename=$imageName");
header("Content-Length: " . filesize("$imageName"));
$fp = fopen("$imageName", "r");
fpassthru($fp);

The passing URL is something like: mydomain/download_image.php?c=atherothrombosis&i=embolus-carotid-artery-illustration

Please suggest solution. Thanks.

还添加此标头

header("Content-Type: application/force-download");

I managed to do so by using below code:

<?php 
$imageName = $_GET['i'];$imageName = $imageName . '-HR.jpg';
$imageCatName = $_GET['c'];
$imageCatName  = ucwords($imageCatName);
$file_path = $docRoot . '/static/media/images/content/image_library/'.$imageCatName . '/'. $imageName;
if(file_exists($file_path)) {
header("Content-disposition: attachment; filename={$imageName}");
header('Content-type: application/octet-stream'); 
readfile($file_path); 
}else {
echo "Sorry, the file does not exist!";
}
?>

still thanks a lot for your support. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM