利用PHP对文件进行下载:

  public function download(){
       $file = './public/Uploads/fileuri';   //下载文件存放目录  
       if (file_exists($file)) {
           header('Content-Description: File Transfer');
           header('Content-Type: application/octet-stream');
           header('Content-Disposition: attachment; filename="'.basename($file).'"');
           header('Expires: 0');
           header('Cache-Control: must-revalidate');
           header('Pragma: public');
           header('Content-Length: ' . filesize($file));
           readfile($file);
           exit;
       }else{
           echo "文件不存在";
       }

   }
Last modification:November 29th, 2018 at 07:15 pm
If you think my article is useful to you, please feel free to appreciate