Home >Backend Development >PHP Tutorial >如何让IE下载pdf文件而不是直接打开

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

WBOY
WBOYOriginal
2016-06-23 13:45:111508browse

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


回复讨论(解决方案)

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

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 ,这个折腾了我好几天

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn