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

相关文章

mac下使用brew配置环境的步骤分享

首先 开启web共享。 配置 httpd.conf 加入php拓展 /etc/apache2/httpd.conf 如出现 ULIMIT_MAX_FILES="ulimit -S -n...

一些使用频率比较高的php函数

1.产生随机字符串函数 function random($length) { $hash = @#@#; $chars = @#abcdefghijklmnopqrstuvwxyz012...

PHP5中虚函数的实现方法分享

请看下面的代码: 复制代码 代码如下: <?php class A { public function x() { echo "A::x() was called.\n"; } p...

php中动态调用函数的方法

本文实例讲述了php中动态调用函数的方法。分享给大家供大家参考。具体分析如下: php中你可以动态调用函数,分为以下步骤: 1. 定义一个函数 2. 将函数名(字符串)赋值给一个变量...

解析php中die(),exit(),return的区别

die()停止程序运行,输出内容exit是停止程序运行,不输出内容return是返回值die是遇到错误才停止exit是直接停止,并且不运行后续代码,exit()可以显示内容。return...