php檔案下載

來源:互聯網
上載者:User

標籤:ase   result   ges   ati   返回   str   code   pos   close   

<?php        /*    *下載報告    */    public function down_report(){        /*        $result = array("error"=>1,"content"=>‘‘);        if(!session(‘user_id‘)) {            $result[‘error‘] = -1;            $result[‘content‘] = "請先登入";            $result[‘url‘] = "/mobile/user/login";            $this->showMsg($result);        }        $url = yf_empty($_POST[‘url‘], ‘‘, true);        if(!$url) {            $result[‘content‘] = "非法參數";            $this->showMsg($result);        }        */    /*                if(1==1){            $result[‘error‘] = 1;            $result[‘content‘] = $url;            $this->showMsg($result);        }    */                        /* 下載開始 */        $url = yf_empty($_GET[‘url‘], ‘‘, true);        if(!$url){            echo "檔案參數錯誤";            exit;        }        $filename = basename($url);    //檔案名稱        $filepath = $_SERVER[‘DOCUMENT_ROOT‘].$url;    //檔案絕對路徑               if(!file_exists($filepath)){           $result[‘error‘] = 1;           $result[‘content‘] = "檔案不存在";        }               $fp = fopen($filepath,"r+");        //開啟檔案流        $filesize = filesize($filepath);               //$filearr = explode(".",$filename);        //$prefix = $filearr[0];    //檔案首碼        //$suxfix = $filearr[1];    //檔案尾碼        header("Content-Type:application/octet-stream");        header("Accept-Ranges:bytes");        header("Accept-Length:".$filesize);        header("Content-Disposition:attachment;filename=".$filename);        header("Pragma:no-cache");    //不緩衝        header("Expires:0");        $buffer=1024;        $filecount=0;               //向瀏覽器返回資料        while(!feof($fp) && $filecount<$filesize){           $filecon = fread($fp,$buffer);           $filecount += $buffer;           echo $filecon;        }        fclose($fp);    }    ?>

 

php檔案下載

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.