ajax下載文件的方法 php下載圖片的方法


PHP下載文件的方法 ajax也是用這種方式 鏈接跳轉就可以了

 

 public function xiazai()
    {
        $file_path = __DIR__ . '/../../../Public/qitan.pdf';


        $fp        = fopen($file_path, "r");
        $file_size = filesize($file_path);
//下載文件需要用到的頭
        Header("Content-type: application/octet-stream");
        Header("Accept-Ranges: bytes");
        Header("Accept-Length:" . $file_size);
        Header("Content-Length:" . $file_size);
        Header("Content-Disposition: attachment; filename=qitan.pdf");

        $buffer     = 1024;
        $file_count = 0;
//向瀏覽器返回數據
        while (!feof($fp) && $file_count < $file_size) {
            $file_con = fread($fp, $buffer);
            $file_count += $buffer;
            echo $file_con;
        }
        fclose($fp);
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM