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二分查找算法。分享给大家供大家参考,具体如下: binarySearch 二分查找采用的方法比较容易理解,以数组为例: ① 先取数组中间的值floor((low+to...

PHP实现基于3DES算法加密解密字符串示例

PHP实现基于3DES算法加密解密字符串示例

本文实例讲述了PHP实现基于3DES算法加密解密字符串。分享给大家供大家参考,具体如下: 3DES(或称为Triple DES)是三重数据加密算法(TDEA,Triple Data En...

用PHP获取Google AJAX Search API 数据的代码

http://code.google.com/apis/ajaxsearch/documentation/ 复制代码 代码如下: // This example request incl...

PHP反射类ReflectionClass和ReflectionObject的使用方法

PHP中的扩展反射类,该扩展用来分析php程序,导出或提取出关于类、方法、属性、参数等的详细信息,包括注释。看一个这样的问题,php类的成员变量没有在类中声明,而是在函数中声明,有什么不...

php中根据变量的类型 选择echo或dump

此时,is_scalar内置函数就派上用场了。 is_scalar -- 检测变量是否是一个标量 标量变量是指那些包含了 integer、float、string 或 boolean的变...