php强制下载文件函数

public function down() { $id = $this->_get('id'); $M = M("downloads"); $data=$M->where("id=$id and status=1")->find(); !$data && exit; $filename = iconv('UTF-8','GBK',$data['filename']); $savename = $data['savename']; $myfile = $data[url] ? $data[url] : 'Uploads/file/'.$savename; if(file_exists($myfile)){   $M->where("id=$id")->setInc('downloads');   $file = @ fopen($myfile, "r");   header("Content-type: application/octet-stream");   header("Content-Disposition: attachment; filename=" .$filename );   while (!feof($file)) { echo fread($file, 50000);   }   fclose($file);   exit; }else{   echo '文件不存在!'; } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/a262f322a814a4340eef659b0780c3c5.html