下载与PHP一起提供的大(ish)压缩邮件对于连接速度慢的人来说已损
我是新手,所以我会尽力解释我遇到的问题.如果我遗漏或不清楚,我会事先道歉.
我在我的根目录之外提供一个81MB的zip文件给那些事先经过验证的人.我一直在收到有关下载损坏或无法完成下载的报告.如果我模拟慢速连接,我已经在我的机器上验证了这一点. 我在运行Apache-Coyote / 1.1的共享主机上. 我收到网络超时错误.我认为我的主持人如果花了太长时间可能会杀死下载,但他们没有以任何方式验证. 我以为我可能遇到内存限制或时间限制,所以我的主机安装了apache模块XSendFile.验证后处理下载的文件中的标题是这样设置的: <?php set_time_limit(0); $file = '/absolute/path/to/myzip/myzip.zip'; header("X-Sendfile: $file"); header("Content-type: application/zip"); header('Content-Disposition: attachment; filename="' . basename($file) . '"'); 任何帮助或建议将不胜感激.谢谢! 解决方法
我建议你看一下这个评论:
http://www.php.net/manual/en/function.readfile.php#99406 特别是,如果你使用的是apache.如果不是,上面链接中的代码应该有用:
编辑 只是为了引用代码来执行“分块”Link to Original Code: <?php function readfile_chunked ($filename,$type='array') { $chunk_array=array(); $chunksize = 1*(1024*1024); // how many bytes per chunk $buffer = ''; $handle = fopen($filename,'rb'); if ($handle === false) { return false; } while (!feof($handle)) { switch($type) { case'array': // Returns Lines Array like file() $lines[] = fgets($handle,$chunksize); break; case'string': // Returns Lines String like file_get_contents() $lines = fread($handle,$chunksize); break; } } fclose($handle); return $lines; } ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |