“Php图像另存为”对话框


Php Image save as dialog box

我想在单击图像时打开一个保存图像对话框。我设法打开了同样的,但保存时,它不会保存打开保存的图像,因为图像的内容没有以某种方式保存。

PHP代码:

$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);

传递的URL类似于:mydomain/download_image.php?c=动脉粥样硬化血栓形成&i=栓塞颈动脉图示

请提出解决方案。谢谢

同时添加此标头

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

我通过使用以下代码做到了这一点:

<?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!";
}
?>

仍然非常感谢您的支持。:)