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

相关文章

phpmyadmin配置文件现在需要绝密的短密码(blowfish_secret)的2种解决方法

解决办法有两种:(建议用第二种) 1、配置phpmyadmin下的config.inc.php  将cookie改为http复制代码 代码如下:vi /usr/share/ph...

在PHP中利用wsdl创建标准webservice的实现代码

1、创建wsdl 说明: A、非标准的webservice,可能只能PHP才能访问 B、标准的webservice,就必须要使用wsdl(webservice description l...

php 5.4 全新的代码复用Trait详解

php 5.4 全新的代码复用Trait详解

从PHP的5.4.0版本开始,PHP提供了一种全新的代码复用的概念,那就是Trait。Trait其字面意思是"特性"、"特点",我们可以理解为,使用Trait关键字,可以为PHP中的类添...

替换php字符串中的单引号为双引号的方法

实例如下: $param = "{'id':'12', 'name':'hi'}"; $new = preg_replace('/\"/', '"', $param); 以上这篇...

php+Ajax处理xml与json格式数据的方法示例

本文实例讲述了php+Ajax处理xml与json格式数据的方法。分享给大家供大家参考,具体如下: 一、ajax如何处理xml数据格式 register.php 只需修改上一篇《php+...