繁体   English   中英

“ 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 = atherothrombosis&i = embolus-carotid-artery-illustration

请提出解决方案。 谢谢。

还添加此标头

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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