当前位置:Gxlcms > PHP教程 > phpreadfile函数下载文件并判断权限的代码示例

phpreadfile函数下载文件并判断权限的代码示例

时间:2021-07-01 10:21:17 帮助过:25人阅读

  1. /**
  2. * header与readfile函数应用举例
  3. * 下载文件 判断权限
  4. * edit bbs.it-home.org
  5. */
  6. $file = get_file_address();// 文件的真实地址(支持url,不过不建议用url)
  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(); //注意此函数的调用,清空但不关闭输出缓存,否则下载的文件头两个字符会是0a
  18. flush();
  19. readfile($file); // 输出文件内容
  20. }
  21. ?>

人气教程排行