Php图像另存为对话框

时间:2012-01-11 05:35:41

标签: php image http-headers

我想点击图片时打开一个保存图像对话框。我设法打开相同但保存后,它不保存打开保存的图像,因为图像的内容不以某种方式保存。

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 =栓子-颈动脉-说明

请建议解决方案。感谢。

2 个答案:

答案 0 :(得分:2)

还添加此标题

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

答案 1 :(得分:2)

我设法使用以下代码:

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

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

相关问题