成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

一個PHP文件下載類

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;
        }
        //把剩下的讀出來 因為文件的帶下很有很能不是1024 的整數(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();

網(wǎng)站名稱:一個PHP文件下載類
文章位置:http://jinyejixie.com/article16/gdjhdg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設計公司、服務器托管網(wǎng)站導航、全網(wǎng)營銷推廣、網(wǎng)站營銷、靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運營
云安县| 吉木乃县| 商城县| 漳浦县| 阳新县| 建始县| 新宁县| 桃江县| 双桥区| 漳浦县| 丹东市| 沙坪坝区| 西昌市| 南安市| 贺兰县| 德庆县| 江城| 宝丰县| 乐亭县| 枞阳县| 玉门市| 清苑县| 信丰县| 泰和县| 绵竹市| 白水县| 聂荣县| 皋兰县| 南木林县| 竹北市| 宁陕县| 威远县| 华蓥市| 邓州市| 五原县| 荃湾区| 郴州市| 靖安县| 家居| 和田县| 建瓯市|