Home > Backend Development > PHP Tutorial > PHP 下载 求指点解决办法

PHP 下载 求指点解决办法

WBOY
Release: 2016-06-13 13:30:46
Original
800 people have browsed it

PHP 下载 求指点
$file="Koala.jpg";

if(file_exists($file)){
header('Content-Description: File Transfer');//应该是内容简介 对应的是什么不太清楚
header('Content-Type: application/octet-stream'); //文件类型,以八位字节流
header('Content-Disposition: attachment; filename='.basename($file)); //下载一个当前目录下的文件名为$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();

}


?>

这是我在网上荡的一个 成功的下载代码 我已经测试过了。

但是由于手册上面提供的void header ( string string [, bool replace [, int http_response_code]] )
并没有太过于详细的介绍 所以我猜测了一下代码的大体意思


上面的那段header 是否是弹出 下载提示框的 信息? 希望有高手能给点详细的

------解决方案--------------------
下载只要有主要几项就可以:

PHP code

$file = 'ASDFGgg.pdf';
_Download("files_dir/".$file, $file);

function _Download($f_location,$f_name){
   header('Content-Type: application/octet-stream');
   header('Content-Length: ' . filesize($f_location));
   header('Content-Disposition: attachment; filename=' . basename($f_name));
   readfile($f_location); 
 } <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template