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 $switching = array( 10, // key =...

php中的MVC模式运用技巧

php中的MVC模式运用 首先我来举个例子: 一个简单的文章显示系统 简单期间,我们假定这个文章系统是只读的,也就是说这个例子将不涉及文章的发布,现在开始了。 由于只涉及数据库的读取,所...

php 生成文字png图片的代码

复制代码 代码如下: <? /* php生成文字png图片,可以使用如下方式调用函数: http://www.yourdomian.com/text_png.php3?msg=he...

PHP实现的随机红包算法示例

PHP实现的随机红包算法示例

本文实例讲述了PHP实现的随机红包算法。分享给大家供大家参考,具体如下: 一、整体设计 算法有很多种, 可以自行选择, 主要的"架构" 是这样的, 用redis decr()命令去限流,...

PHP进程通信基础之信号

使用信号通信。可以使用kill -l 来查看当前系统的信号类型。 每个信号所代表的的详细含义,请查看我的这篇文章:https://www.jb51.net/article/106040...