热搜:NVER node 开发 php

如何让IE下载pdf文件而不是直接打开

2024-08-17 17:35:01
如何让IE下载pdf文件而不是直接打开

比如在某服务器上有一个pdf文件:http://www.xxx.com/abc.pdf
然后 abc,在IE下点击超链接,会直接打开这个pdf文件,请问在IE下怎样才能弹出下载框而不是直接打开?用php(或js)怎样做?


回复讨论(解决方案)

<?phpheader("content-type: text/html;charset=utf-8");echo '点击下载';?>

oo.php

$file_path='test.pdf';$file_name='test.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-Disposition:attachment;filename=".$file_name);$buffer=1024;$file_count=0;while(!feof($fp) && ($file_size-$file_count>0)){	$file_data=fread($fp,$buffer);	$file_count+=$buffer;	echo $file_data;}fclose($fp);

多谢 jam00 ,这个折腾了我好几天