无法在 Windows 中解压大型 Linux 压缩存档

Unable to unzip large Linux zipped archive in Windows

服务器环境:

客户端环境:

场景如下:

问题是当我尝试打开下载的zip时,我添加的xml是"missing",7zip报告说是there are data after the payload。如果我在服务器端解压完全相同的 zip,所有东西都在那里...如果我 scp 将 zip 到我的本地机器,然后转移到我的 Windows 机器,并在那里打开它,也很好...

这让我想到,我设置的header可能是错误的...我尝试了各种不同的方法,但仍然无法解决...这是最新的header 我有...

ob_start();
header("Content-type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
header('Content-Length: ' . filesize($filename));
header("Content-Disposition: attachment; filename=\"$filename\"");
while (ob_get_level()) {
   ob_end_clean();
}
readfile($filename);

我也试过 application/zip,也没有用。

更新:

因此,如果我通过浏览器 (IE11) 下载 zip 文件,文件的校验和与服务器上生成的 zip 不同...如果我 scp 从服务器到本地的 zip,然后对其进行校验和,它们匹配...所以看起来在传输过程中有东西破坏了 zip,但这只发生在 zip 中的大文件。

谁能告诉我为什么这个大文件的属性 stor 与其他文件不同?为什么我添加的 xml 有 0.0 fat 而其他的有 6.3?

less 123456.zip
-rw-a--     6.3 fat      140 bx defN  3-Feb-16 12:22 123456/CONFIG.LDR
-rw-a--     6.3 fat      140 bx defN  8-Apr-16 10:55 123456/FILES.LUM
-rw-a--     6.3 fat      100 bx defN  3-Feb-16 12:23 123456/LOADS.LUM
-rw-a--     6.3 fat 2621440000 bx stor 16-Feb-17 15:09 123456/huge.lup
-rw-a--     6.3 fat      142 bx defN  3-Feb-16 12:23 123456/PBA123456.LUH
-rw----     0.0 fat    25196 b- defN 17-Feb-17 16:13 123456/crate.xml
6 files, 2621465718 bytes uncompressed, 2621451952 bytes compressed:  0.0%

我注意到在通过浏览器下载文件后,大文件之后的所有内容(例如:LUH 和 xml)都丢失了。

更新2:

好吧,这太疯狂了...所以我用 unzip 在 linux 上解压缩 zip,然后使用 zip 重新打包并通过浏览器以相同的方式下载文件。我现在正在丢失存档中的不同文件...这绝对是零感觉!

在我解压并重新打包后,我得到了下面这个,大文件之后的所有内容在 Windows.

中是不可见的
drwxr-xr-x  2.3 unx        0 bx stor 17-Feb-17 17:03 123456/
-rw-r--r--  2.3 unx      140 bx defN  8-Apr-16 10:55 123456/FILES.LUM
-rw-r--r--  2.3 unx      142 bx defN  3-Feb-16 12:23 123456/PBA123456.LUH
-rw-r--r--  2.3 unx    25196 tx defN 17-Feb-17 16:51 123456/crate.xml
-rw-r--r--  2.3 unx 2621440000 bx defN 16-Feb-17 15:09 123456/huge.lup
-rw-r--r--  2.3 unx      100 bx defN  3-Feb-16 12:23 123456/LOADS.LUM
-rw-r--r--  2.3 unx      140 tx defN  3-Feb-16 12:22 123456/CONFIG.LDR

PHP readfile() 处理大文件时可能会出现问题。尝试使用 stream_copy_to_stream() 代替:

set_time_limit(0);
$stdout = fopen('php://output', 'w');
$bfname = basename($fname);

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$bfname\"");

$filein = fopen($fname, 'r');
stream_copy_to_stream($filein, $stdout);

fclose($filein);
fclose($stdout);