PHP Download File Method Example Tutorial
PHP download file Two ways to share with the code
Transferred from: http://www.cnblogs.com/cfinder010/p/3197195.html
PHP implements two ways to download files. Sharing, useful to the friends to see OH.
Method One:
PHP
/** * Download File * Header function **/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);?>
The above code uses the PHP header function, you can refer to the following article:
A simple example of the PHP header () function
PHP header function Implementation of file download instance code
An example of the use of header functions in PHP
PHP Header Use detailed
PHP header function File download direct prompt to save the code
PHP header function Implementation of text file download method
PHP file Header (header) information detailed
PHP uses the header to send various types of file download examples
Learn about the use of header functions in PHP.
Method Two:
Php//File Download//readfile$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();?>