当前位置:Gxlcms > PHP教程 > php读取文件更改文件名后提供下载

php读取文件更改文件名后提供下载

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

<无详细内容>
  1. $filename = dirname(__FILE__) . '/oldfilename.exe';
  2. $out_filename = 'newfilename.exe';
  3. if()) {
  4. echo 'Not Found' . $filename;
  5. exit;
  6. } else {
  7. // We'll be outputting a file
  8. @header('Accept-Ranges: bytes');
  9. @header('Accept-Length: ' . filesize($filename));
  10. // It will be called
  11. @header('Content-Transfer-Encoding: binary');
  12. @header('Content-type: application/octet-stream');
  13. @header('Content-Disposition: attachment; filename=' . $out_filename);
  14. @header('Content-Type: application/octet-stream; name=' . $out_filename);
  15. // The source is in filename
  16. $file = @fopen($filename, "r");
  17. echo @fread($file, @filesize($filename));
  18. @fclose($file);
  19. exit;
  20. }

人气教程排行