首页 > Web开发 > 详细

php header 设置文件下载

时间:2016-06-22 18:53:02      阅读:203      评论:0      收藏:0      [点我收藏+]
控制器 php 代码:
$filepath = "http://www.jiesen365.com/uploadfile/20150519044903-897.pdf";   //下载文件地址

$arr = explode( ‘/‘ , $filepath);
$filename= $arr[count($arr)-1]; //设置下载文件名称,注意后缀名

if($filepath){
header("Content-type: text/plain");
header("Accept-Ranges: bytes");
header("Content-Disposition: attachment; filename=".$filename);
header("Cache-Control: must-revalidate, post-check=0, pre-check=0" );
header("Pragma: no-cache" );
header("Expires: 0" );
readfile($filepath);
exit(0);
}

前台html代码:

<a href="javascript:;" onclick="download()">点击下载</a>

function download(){

  window.location.href="连接--访问控制器(自动下载)"
}




php header 设置文件下载

原文:http://www.cnblogs.com/isungge/p/5607849.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!