php让浏览器是下载pdf而不是打开
有的浏览器安装了pdf打开程序关联到浏览器,所以直接写上pdf路径时是打开pdf而不是下载,下面我就说下如果让他们只是下载,而不是浏览,创建一个php文件,代码如下:
<?php $file = $_GET['file']; $arr = explode('/',$file); header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="'.array_pop($arr).'"'); readfile(file); ?>
加入代码,通过这个把pdf路径转换成浏览器认识的语言,告诉浏览器列子 /upload.php?file=/aa/aa.pdf,这样就可以不管是什么,都会下载,而不是打开.
文章链接:http://www.phprm.com/scxz/fs3640.html
随便收藏,请保留本文地址!