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

WBOY
Release: 2016-06-23 13:45:11
Original
1471 people have browsed it

比如在某服务器上有一个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>';?>
Copy after login

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);
Copy after login

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!