Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.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_Download_Types - Fatal编程技术网

Php 页面内容类型

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

我有一个指向图片的页面链接列表。当我点击一些图片时,它会在浏览器中打开,我需要使其可下载(使用“必须查看”窗口保存图片)。正如我所理解的,我必须制作脚本(仅限于php),并在链接地址时使用它,将图像名称传递给它。然后,以某种方式更改内容类型页面,并要求用户下载文件。 你能帮我写这个脚本吗?

来自


来自


<?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);
}
?>