php文件下载方法收藏(附js下载技巧)

function down($url){
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($papers['file_path']));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . $url);
        readfile('location:http://你的域名/'.$url);
    }

 

这里就不过多的写文字了,相信都能看懂。就算看不懂,会用就行,$url是文件链接。

 

还有一个javascript下载不打开的小技巧(加一个download属性即可),找了好多办法,都行不通。这里也记录下吧

<a href="文件链接" download="" target="_blank" title="下载检测报告" >点我下载</a>

 

posted @ 2018-09-05 13:37  知风阁  阅读(815)  评论(0编辑  收藏  举报