gpt4 book ai didi

php - 大型 .zip 文件下载不完整

转载 作者:可可西里 更新时间:2023-11-01 16:47:07 26 4
gpt4 key购买 nike

我是一个重度新手,但是我在发帖之前做了很多研究,所以我希望你能提供帮助。

我正在尝试提供托管在 Apache 服务器上的大型 .zip 文件,大约 6.4 Gb。该文件在浏览器中显示已完成下载,但实际上只下载了大约 500Mb。这似乎是一个非常普遍的问题,并且在网上找到了很多其他帖子和信息,但这个问题对我来说一直存在。

Large Zip file offered for download using php

IE download incomplete even though it claims success

Large zip downloads failing only in IE

我一直在使用 Chrome 39.0.2171.71 进行测试,但我在使用 FireFox 和 IE 时遇到了同样的问题。我认为我的文件比其他人发布的文件大得多,因此他们的解决方案可能对这种情况有所帮助,但没有解决根本问题。我有第二个 .zip 文件,大约 400Mb,我成功地使用了相同的 http header 。

我找到的最有用的文章是:http://perishablepress.com/http-headers-file-downloads/并且我从该来源复制了下面显示的大部分 php,因为该网站上的其他张贴者似乎也这样做了。

我也尝试过使用 X-SendFile,但我认为我的虚拟主机没有安装合适的 Apache 模块。我花了一整天的时间来研究这个,并且已经没有想法了!我成功地使用了下载管理器,我不知道这是偶然还是什么,但我不想要求我的客户必须下载并安装单独的程序才能获取 .zip 文件。

<?php 
// HTTP Headers for ZIP File Downloads

// set example variables
$filename = "huge.zip";
$filepath = "****";

// http headers for zip downloads
// header("X-Sendfile: $filepath$filename");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filepath.$filename));
set_time_limit(0);
ob_end_flush();
@readfile($filepath.$filename);
?>

这是我运行上面的 php 时的响应 header

Remote Address:76.162.142.242Request URL:****/GetSW.phpRequest Method:GETStatus Code:200 OKRequest HeadersAccept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Accept-Encoding:gzip, deflate, sdchAccept-Language:en-US,en;q=0.8Authorization:Basic ******Connection:keep-aliveCookie:_ga=GA1.2.1176828605.1417985823DNT:1Host:www.teamursa.orgReferer:http://www.teamursa.org/****.htmlUser-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36Response HeadersCache-Control:publicConnection:Keep-AliveContent-Description:File TransferContent-Disposition:attachment; filename="huge.zip"Content-Length:6720560824Content-Transfer-Encoding:binaryContent-Type:application/octet-streamDate:Sun, 07 Dec 2014 22:16:57 GMTExpires:0Keep-Alive:timeout=3, max=120Pragma:publicServer:ApacheX-Powered-By:PHP/5.2.17

最佳答案

您可能需要增加服务器上的内存限制。在开始的 PHP 标记之后尝试下面的操作

ini_set('memory_limit','16M');

然后从 16M 继续增加

关于php - 大型 .zip 文件下载不完整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27348624/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com