php 强制下载文件实现代码

yipeiwu_com6年前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");
?>

相关文章

windows环境下php配置memcache的具体操作步骤

windows环境下php配置memcache的具体操作步骤

首先要安装好php和apache环境。我用的是wamp整合的套件php 5.2.8apache 2.2.1.1这些都准备好了后,就到 memcache 官网去下载 windows 下的...

php使用Cookie实现和用户会话的方法

本文实例讲述了php使用Cookie实现和用户会话的方法。分享给大家供大家参考。具体分析如下: PHP 包含了很多的函数,可以用来管理和记录用户信息,包括简单的 cookie 和全方位的...

解析PHP中的unset究竟会不会释放内存

首先让我们看一个例子复制代码 代码如下:    var_dump(memory_get_usage());    $a = "...

PHP单元测试利器 PHPUNIT深入用法(三)第1/2页

PHP单元测试利器 PHPUNIT深入用法(三)第1/2页

在本文中,笔者将为大家介绍phpunit中的两个高级概念和用法,尽管它不一定在你的日常单元测试中都用到,但理解和学会它们的用法对学习phpunit还是十分重要的。   Phpunit中...

PHP简单获取及判断提交来源的方法

本文实例讲述了PHP简单获取及判断提交来源的方法。分享给大家供大家参考,具体如下: echo $_SERVER['HTTP_REFERER']; 这个获取上个页面的url 例如...