PHP uses the readfile function to determine download file permissions_PHP tutorial

WBOY
Release: 2016-07-13 17:45:18
Original
886 people have browsed it

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...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!