[PHP] PHP实现文件下载功能 →→→→→进入此内容的聊天室

来自 , 2019-08-03, 写在 PHP, 查看 106 次.
URL http://www.code666.cn/view/05b8caaf
  1. <?php
  2. $base_dir = "/usr/share/nginx/html/";
  3. $myfile = $base_dir . $_GET["file"];
  4. //echo $myfile;
  5.  
  6. if( ! file_exists($myfile) ) {
  7. echo "file: " . $myfile . " doesn't exist.";
  8. } elseif ( is_dir($myfile) ) {
  9. echo "file: " . $myfile . " is a directory.";
  10. } else {
  11.     header("Content-type: application/octet-stream");
  12.     header('Content-Disposition: attachment; filename="' . basename($myfile) . '"');
  13.     header("Content-Length: ". filesize($myfile));
  14.     readfile($myfile);
  15. }
  16. ?>

回复 "PHP实现文件下载功能"

这儿你可以回复上面这条便签

captcha