Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“Php图像另存为”对话框_Php_Image_Http Headers - Fatal编程技术网

“Php图像另存为”对话框

“Php图像另存为”对话框,php,image,http-headers,Php,Image,Http Headers,我想在单击图像时打开“保存图像”对话框。我设法打开相同的,但当保存时,它不会保存打开保存的图像,因为图像的内容不知何故没有保存 PHP代码: $imageName = $_GET['i']; $imageName = $imageName . '-HR.jpg'; header ("Content-Type: application/download"); header ("Content-Disposition: attachment; filename=$imageName"); heade

我想在单击图像时打开“保存图像”对话框。我设法打开相同的,但当保存时,它不会保存打开保存的图像,因为图像的内容不知何故没有保存

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=颈动脉栓子图示

请提出解决方案。谢谢。

也添加此标题

标题(“内容类型:应用程序/强制下载”)

也添加此标题


标题(“内容类型:应用程序/强制下载”)

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

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


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

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

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


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

有什么保存吗?即使它不是一个有效的图像?如果是的话,那是什么!有什么保存吗?即使它不是一个有效的图像?如果是的话,那是什么!