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

相关文章

PHP记录页面停留时间的方法

本文实例讲述了PHP记录页面停留时间的方法。分享给大家供大家参考,具体如下: 首先在要监控的页面添加JS如下 <script> var dt1 = new Date();...

解析WordPress中控制用户登陆和判断用户登陆的PHP函数

登陆函数:wp_signon() 函数介绍: wp_signon()函数用于授权给用户登陆wordpress并可记住该用户名称。该函数取代了wp_login。WordPress 2.5版...

php删除左端与右端空格的方法

本文实例讲述了php删除左端与右端空格的方法。分享给大家供大家参考。具体方法如下: 在php中删除函数比js要具体很多,除了trim()函数,还有ltrim()和rtrim()函数,他们...

php判断表是否存在的方法

本文实例讲述了php判断表是否存在的方法。分享给大家供大家参考。具体如下: <?php //方法一 mysql_connect('localhost','root'...

PHP面向对象程序设计子类扩展父类(子类重新载入父类)操作详解

本文实例讲述了PHP面向对象程序设计子类扩展父类(子类重新载入父类)操作。分享给大家供大家参考,具体如下: 在PHP中,会遇到这样的情况,子类继承父类,但是又需要对父类的属性和方法进行一...