Home >Backend Development >PHP Tutorial >Two ways to parse PHP to download files_PHP tutorial

Two ways to parse PHP to download files_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:01:10841browse

方法一:

复制代码 代码如下:

 header('Content-Description: File Transfer');
 header('Content-Type: application/octet-stream');
 header('Content-Disposition: attachment; filename='.basename($filepath));
 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($filepath));
 readfile($file_path);

方法二:
复制代码 代码如下:

 $fileinfo = pathinfo($filename);
 header('Content-type: application/x-'.$fileinfo['extension']);
 header('Content-Disposition: attachment; filename='.$fileinfo['basename']);
 header('Content-Length: '.filesize($filename));
 readfile($thefile);
 exit();

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/328007.htmlTechArticle方法一: 复制代码 代码如下: header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; fil...
Statement:
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