标签:
1 public function downLoad(){ 2 $torrent_name=$this->_get(‘torrent_name‘); 3 $fileName=‘./Public/Admin/download/‘.$torrent_name; 4 if(file_exists($fileName)){//下载 5 $fp=fopen($fileName,‘rb‘); 6 if(!$fp){ 7 header(‘HTTP/1.1 404 Not Found‘); 8 echo "Error: 404 Not Found.(server file path error)<!-- Padding --><!-- Padding --><!-- Padding --><!-- Padding --><!-- Padding --><!-- Padding --><!-- Padding --><!-- Padding --><!-- Padding --><!-- Padding --><!-- Padding --><!-- Padding --><!-- Padding --><!-- Padding -->"; 9 exit; 10 } 11 $encoded_filename = urlencode($fileName); 12 $encoded_filename = str_replace("+", "%20", $encoded_filename); 13 $fileSize=@filesize($fileName); 14 $fileName=basename($fileName); 15 header(‘HTTP/1.1 200 OK‘); 16 header( "Pragma: public" ); 17 header( "Expires: 0" ); 18 header("Content-type: application/octet-stream"); 19 header("Accept-Ranges: bytes"); 20 header("Accept-Length: ".$fileSize); 21 $ua = $_SERVER["HTTP_USER_AGENT"]; 22 if(preg_match("/MSIE/", $ua)) { 23 header(‘Content-Disposition: attachment; filename="‘ . $encoded_filename . ‘"‘); 24 }else if (preg_match("/Firefox/", $ua)) { 25 header(‘Content-Disposition: attachment; filename*="utf8\‘\‘‘ . $fileName . ‘"‘); 26 }else{ 27 header(‘Content-Disposition: attachment; filename="‘ . $fileName . ‘"‘); 28 } 29 while(!feof($fp)){ 30 $file_data=fread($fp,1024); 31 echo $file_data; 32 } 33 fclose($fp); 34 exit; 35 }else{ 36 $this->error(‘文件信息不存在!‘);exit; 37 } 38 }
标签:
原文地址:http://www.cnblogs.com/719907411hl/p/4551187.html