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获取文件后缀名(format file) //方法一:   复制代码 代码如下:<?php     function&nbs...

PHP精确计算功能示例

本文实例讲述了PHP精确计算功能。分享给大家供大家参考,具体如下: 引言:一定要确保数据的准确性。这是一个好的程序员的基本素养。 <?php /** * 精确加法...

php 远程关机操作的代码

<?php /** * 远程启动计算机 * 注意:iis/apache需要有windows/system/cmd.exe执行权限 * name:薛如飞 * qq:6706250 *...

PHP 匿名函数与注意事项详细介绍

PHP 匿名函数与注意事项 PHP5.2 以前:autoload, PDO 和 MySQLi, 类型约束 PHP5.2:JSON 支持 PHP5.3:弃用的功能,匿名函数,新增魔术方法,...

PHP写日志的实现方法

本文实例讲述了PHP写日志的实现方法。分享给大家供大家参考。具体实现方法如下: 复制代码 代码如下:function logError($content)  { ...