Sample code for the phpreadfile function to download files and determine permissions

Source: Internet
Author: User
Sample code for the phpreadfile function to download files and determine permissions

  1. /**
  2. * Example of applying the header and readfile functions
  3. * Download object judgment permission
  4. * Edit bbs.it-home.org
  5. */
  6. $ File = get_file_address (); // the actual address of the file (url is supported, but url is not recommended)
  7. If (file_exists ($ file ))
  8. {
  9. Header ('content-Description: File Transfer ');
  10. Header ('content-Type: application/octet-stream ');
  11. Header ('content-Disposition: attachment; filename = '. basename ($ file ));
  12. Header ('content-Transfer-Encoding: binary ');
  13. Header ('expires: 0 ');
  14. Header ('cache-Control: must-revalidate, post-check = 0, pre-check = 0 ');
  15. Header ('pragma: public ');
  16. Header ('content-Length: '. filesize ($ file ));
  17. Ob_clean (); // note the call of this function. clear the function but do not disable the output cache. Otherwise, the first two characters of the downloaded file will be 0a.
  18. Flush ();
  19. Readfile ($ file); // output file content
  20. }
  21. ?>

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.