首页  >  文章  >  后端开发  >  header - thinkphp如何实现弹窗下载

header - thinkphp如何实现弹窗下载

WBOY
WBOY原创
2016-06-06 20:52:141046浏览

header("Pragma: public");
header("Cache-control: max-age=".$expire);

//header('Cache-Control: no-store, no-cache, must-revalidate');
header("Expires: " . gmdate("D, d M Y H:i:s",time() $expire) . "GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s",time()) . "GMT");
header("Content-Disposition: attachment; filename=".$showname);
header("Content-Length: ".$length);
header("Content-type: ".$type);
header('Content-Encoding: none');
header("Content-Transfer-Encoding: binary" );
if($content == '' ) {
readfile($filename);
}else {
echo($content);
}
exit();

这是http里面的一段代码,可是我用它只能读出到浏览器中。请问有什么方法点击链接如“下载”便出现一个弹框然后自己输入保存名字存起来呢?

回复内容:

header("Pragma: public");
header("Cache-control: max-age=".$expire);

//header('Cache-Control: no-store, no-cache, must-revalidate');
header("Expires: " . gmdate("D, d M Y H:i:s",time() $expire) . "GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s",time()) . "GMT");
header("Content-Disposition: attachment; filename=".$showname);
header("Content-Length: ".$length);
header("Content-type: ".$type);
header('Content-Encoding: none');
header("Content-Transfer-Encoding: binary" );
if($content == '' ) {
readfile($filename);
}else {
echo($content);
}
exit();

这是http里面的一段代码,可是我用它只能读出到浏览器中。请问有什么方法点击链接如“下载”便出现一个弹框然后自己输入保存名字存起来呢?

header("Content-type: application/octet-stream;");

或者修改 httpd 的 mime.types 里面对应的文件类型为 application/octet-stream

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn