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