public function index() { $id = (int)input('id'); if(empty($id) || !is_numeric($id)){ $this->error("参数错误"); } $fileinfo = db('files')->where('id',$id)->find(); if(!$fileinfo){ $this->error("文件不存在!"); } $file_url = './uploads/Download/'.$fileinfo['savepath'].$fileinfo['savename']; $out_filename = $fileinfo['name']; if(!file_exists($file_url)) { $this->error("文件不存在!"); }else{ header('Accept-Ranges: bytes'); header('Accept-Length: ' . filesize( $file_url )); header('Content-Transfer-Encoding: binary'); header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $out_filename); header('Content-Type: application/octet-stream; name=' . $out_filename); if(is_file($file_url) && is_readable($file_url)){ $file = fopen($file_url, "r"); echo fread($file, filesize($file_url)); fclose($file); } } }
标签:url,别名,Content,header,TP5,file,fileinfo,PHP,id From: https://www.cnblogs.com/fengluoye/p/16629898.html