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中对多维数组特定列的提取,是个很常用的功能,正因为如此,PHP在5.5.0版本之后,添加了一个...

PHP连接sql server 2005环境配置及问题解决

一、Windows下PHP连接SQLServer 2005 设定:安装的Windows操作系统(Win7 或XP均可,其他系统暂未测试),在C盘下;PHP的相关文件位于c:/PHP下面,...

PHP DB 数据库连接类定义与用法示例

本文实例讲述了PHP DB 数据库连接类定义与用法。分享给大家供大家参考,具体如下: 声明: 近期观看了一节 PHP 消息队列视频,对于讲师WiconWang提供的代码,在此分享一下,希...

PHP下编码转换函数mb_convert_encoding与iconv的使用说明

不过英文一般不会存在编码问题,只有中文数据才会有这个问题。比如你用Zend Studio或Editplus写程序时,用的是gbk编码,如果数据需要入数据库,而数据库的编码为utf8时,这...

php2html php生成静态页函数

<?php /** ------------------------ Function: php2html($in_Url, $out_htmlFile, $out_logFile...