控制器 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="连接--访问控制器(自动下载)"
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步