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文件读取操作相对于文件写入操作涉及更多的PHP文件操作函数,在代码实例中会详细介绍这些函数。   读取文本文件中存储数据的方式主要涉及的三个步骤及部分文件操作函数如下:   1、打...

PHP微信模板消息操作示例

本文实例讲述了PHP微信模板消息操作方法。分享给大家供大家参考,具体如下: 微信SDK: <?php class Oauth { //获得全局access_toke...

解析PHP 5.5 新特性

PHP5.5 前不久前刚刚发布,里面的新特性有什么?官方文档在这里:http://www.php.net/manual/zh/migration55.new-features.php1...

PHP strripos函数用法总结

php strripos()函数 语法 作用:寻找某字符串中某字符最后出现的位置,不区分大小写 语法: strripos(string,find,start) 参数: string...

ThinkPHP中自定义目录结构的设置方法

ThinkPHP中自定义目录结构的设置方法

效果如图所示: 入口文件 <?php // 应用入口文件 // 检测PHP环境 if(version_compare(PHP_VERSION,'5.3.0','&...