首頁 >後端開發 >php教程 >php讀取檔 更改檔名後提供下載

php讀取檔 更改檔名後提供下載

WBOY
WBOY原創
2016-07-25 09:02:34965瀏覽
  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. }
复制代码


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn