php 强制下载文件实现代码

yipeiwu_com5年前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);
    exit;
}
?>
?
<?php
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=ins.jpg"); 
readfile("imgs/test_Zoom.jpg");
?>

相关文章

php实现上传图片保存到数据库的方法

php实现上传图片保存到数据库的方法

php实现上传图片保存到数据库的方法。分享给大家供大家参考。具体分析如下: php 上传图片,一般都使用move_uploaded_file方法保存在服务器上。但如果一个网站有多台服务器...

wordpress自定义标签云与随机获取标签的方法详解

wp_tag_cloud() 函数的作用是用来标签云的,可以根据每个标签所关联的文章次数来定义字体大小、标签排序等属性。从 2.8 版本开始,添加了 分类法(taxonomy)参数,这就...

PHP遍历数组的三种方法及效率对比分析

本文实例分析了PHP遍历数组的三种方法及效率对比。分享给大家供大家参考。具体分析如下: 今天有个朋友问我一个问题php遍历数组的方法,告诉她了几个。顺便写个文章总结下,如果总结不全还请朋...

PHP syntax error, unexpected $end 错误的一种原因及解决

Parse error: syntax error, unexpected $end in script.php on line xx 调试了一会后发现产生错误的行是文件中间某行 //$...

PHP观察者模式定义与用法实例分析

本文实例讲述了PHP观察者模式定义与用法。分享给大家供大家参考,具体如下: 我理解的观察者模式就是,当我们触发一个事件的时候,想要把这个操作告诉给我想要告诉的对象,让他们都执行这个操作,...