Php uses the readfile function to determine the permission to download files

Source: Internet
Author: User
Php code & lt ;? Php $ fileget_file_address (); // the actual address of the file (url is supported, but url is not recommended) if (file_exists ($ file) {header (& amp; #39; content-Description: FileTransfer & amp; #39;); header (& amp; #39;

Php code

$ File = get_file_address (); // the actual address of the file (url is supported, 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 (); // call this function. clear the file but do not disable 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 the "pswzyu technical blog"
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.