Php 页面内容类型
我有一个指向图片的页面链接列表。当我点击一些图片时,它会在浏览器中打开,我需要使其可下载(使用“必须查看”窗口保存图片)。正如我所理解的,我必须制作脚本(仅限于php),并在链接地址时使用它,将图像名称传递给它。然后,以某种方式更改内容类型页面,并要求用户下载文件。 你能帮我写这个脚本吗?来自Php 页面内容类型,php,image,download,types,Php,Image,Download,Types,我有一个指向图片的页面链接列表。当我点击一些图片时,它会在浏览器中打开,我需要使其可下载(使用“必须查看”窗口保存图片)。正如我所理解的,我必须制作脚本(仅限于php),并在链接地址时使用它,将图像名称传递给它。然后,以某种方式更改内容类型页面,并要求用户下载文件。 你能帮我写这个脚本吗?来自 来自 <?php $file = 'monkey.gif'; if (file_exists($file)) { header('Content-Description: File
来自
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
}
?>