as2 / flash :: 如何通过 PHP 强制下载文件
我尝试通过 PHP 强制下载文件,
$ctype="application/zip";
header("Content-Type: $ctype");
header("Content-Length: ".filesize($filepath));
header("Expires: 0");
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); //header("Cache-Control: public");
header("Pragma: public");
header("Content-Disposition: attachment; filename=".$filename);
// header("Location: $filepath"); // edited: removed
readfile($filepath);
但它不起作用。
使用 firebug 我可以看到更改后的标题信息,但没有出现保存文件对话框...
I try to force a file-download via PHP with
$ctype="application/zip";
header("Content-Type: $ctype");
header("Content-Length: ".filesize($filepath));
header("Expires: 0");
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); //header("Cache-Control: public");
header("Pragma: public");
header("Content-Disposition: attachment; filename=".$filename);
// header("Location: $filepath"); // edited: removed
readfile($filepath);
but it doesn't work.
with firebug I can see the changed header information but no save-file dialog appears...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要删除
Which 基本上将您重定向到特定路径而不是读取其内容。
You need to remove
Which is basically redirecting you to the path specific instead of reading it's contents.
sendAndLoad()
将“吃掉”您的响应,并且不会导致下载,这在您尝试加载数据时很有用。但是,在您的情况下,您需要使用getURL()
因为您希望浏览器处理响应,而不是 flash。sendAndLoad()
will "eat" your response and not cause a download which is useful if you're trying to load data. However, in your case you need to usegetURL()
since you want the browser to deal with the response, not flash.