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会帮你完成。 当然,我们可以按自己的意愿调用 u...

php 获取SWF动画截图示例代码

1.下载附件,并安装,方法看附件中的帮助 2.拷贝代码进合适位置,生成图片,怎么处理,自己看着办喽 复制代码 代码如下: $oldswf = "/uploads/swf/test.swf...

php使用curl实现ftp文件下载功能

本文实例为大家分享了php实现ftp文件下载功能,供大家参考,具体内容如下 不知道为什么用正常的ftp_get函数下载文件速度特别慢,但是用ftp的客户端下载很快,所以换了curl的下载...

php设计模式之装饰模式应用案例详解

本文实例讲述了php设计模式之装饰模式。分享给大家供大家参考,具体如下: 介绍 装饰者模式(Decorator Pattern)允许你向一个现有的对象添加新的功能,同时又不改变其结...

PHP实现创建微信自定义菜单的方法示例

本文实例讲述了PHP实现创建微信自定义菜单的方法。分享给大家供大家参考,具体如下: 在使用通用接口前,你需要做以下两步工作: 1.拥有一个微信公众账号,并获取到appid和appsecr...