您好,登錄后才能下訂單哦!
class downLoad{ var $file_name; var $file_dir; var $buffer_size = 1024; var $err = ""; public static $MIME_type = array( "pdf" =>"application/pdf", "exe" =>"application/octet-stream", "zip" =>"application/zip", "doc" =>"application/msword", "xls" =>"application/vnd.ms-excel", "ppt" =>"application/vnd.ms-powerpoint", "gif" =>"p_w_picpath/gif", "png" =>"p_w_picpath/png", "jpeg" =>"jpg", "mp3" =>"audio/mpeg", "wav" =>"audio/x-wav", "mpeg" =>"mpg", "mpe" =>"video/mpeg", "mov" =>"video/quicktime", "avi" =>"video/x-msvideo", ); public function __construct($file_dir="",$file_name=""){ $this->file_dir = $file_dir; $this->file_name = $file_name; $this->path = $file_dir."/".$file_name; $this->suffix = pathinfo($file_name,PATHINFO_EXTENSION); } public function down(){ if(!file_exists($this->path)){ $this->err = "該文件被移除了"; return false; } $content_type = $this->getMIME($this->suffix); $file_size = filesize($this->path); header("Content-type: ".$content_type); header('Content-Disposition: p_w_upload; filename="'.$this->file_name.'"'); @header("Cache-control: public"); @header("Pragma: public"); header("Content-Length: ".$file_size); ob_end_clean(); //readfile($this->path); 一次性讀出來 $fp= fopen($this->path,"r"); $buffer_size = $this->buffer_size; $cur_pos = 0; //記錄讀了多少了 while(!feof($fp) && $file_size>$buffer_size+$cur_pos){ $buffer = fread($fp,$buffer_size); //每次讀1024字節(jié) echo $buffer; $cur_pos += $buffer_size; } //把剩下的讀出來 因?yàn)槲募膸潞苡泻苣懿皇?024 的整數(shù)倍 $buffer = fread($fp,$file_size-$cur_pos); echo $buffer; fclose($fp); return true; } public function getMIME($key=""){ if($key == "" || !isset(self::$MIME_type[$key])){ return "application/octet-stream"; } return self::$MIME_type[$key]; } } // $x = new downLoad($file_dir,$file_name); $file_dir路徑 比如 all $file_name文件名 比如 a.exe 合起來就是全部的路徑了all/a.exe // $x->down();
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。