Home  >  Article  >  Backend Development  >  PHP uses the readfile function to determine download file permissions_PHP tutorial

PHP uses the readfile function to determine download file permissions_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:45:18880browse

Php code

$file = get_file_address(); // The real address of the file (supports url, but url is not recommended)

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(); //The important thing is the call of this function, clear but not close the output cache, otherwise the first two characters of the downloaded file will be 0a
flush();
Readfile($file); // Output file content

?>






-----------------------EOF------------------------

This article is from "pswzyu's technology blog"

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478673.htmlTechArticlePhp code?php $file = get_file_address();//The real address of the file (url is supported, but not recommended Use url) if (file_exists($file)) { header(Content-Description: File Transfer); header...
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