码迷,mamicode.com
首页 > Web开发 > 详细

php header 设置文件下载

时间:2016-06-22 18:54:22      阅读:654      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!