php ie9自动下载
大家好,我正在尝试在人们访问页面时显示一个自动下载框。 我已经在所有浏览器上都可以使用这个功能,现在 ie9 已经出现了,虽然它在最后下载,但它说“此下载被中断”,
这就是我正在使用的代码明智的
// set headers
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"$download[file]\";\n\n");
header( 'Content-Description: File Transfer' );
header("Content-Type: ".$mtype);
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".(string)$size.";\n");
//get a chunk of the file
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
//downloads file
$handle = fopen($download_file, 'rb');
if ($handle === false) {
}
//write to the browser for download
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer);
}
}
exit;
任何想法吗?
Hi guys I'm trying to get an automatic download box to appear when people go a page.
I've got this working on all the browsers and now ie9 has come along and although it downloads at the end it says "This download was interrupted"
this is what I'm using code wise
// set headers
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"$download[file]\";\n\n");
header( 'Content-Description: File Transfer' );
header("Content-Type: ".$mtype);
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".(string)$size.";\n");
//get a chunk of the file
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
//downloads file
$handle = fopen($download_file, 'rb');
if ($handle === false) {
}
//write to the browser for download
while (!feof($handle)) {
$buffer = fread($handle, $chunksize);
echo $buffer;
ob_flush();
flush();
if ($retbytes) {
$cnt += strlen($buffer);
}
}
exit;
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是使用 readfile 代替您正在执行的有些复杂的文件输出:
看看是否可以作品。
Instead of the somewhat complicated file output you're doing, I'd just use readfile instead:
See if that works.