我正在尝试使用php从apache下载整个目录 我使用这个问题的答案Zip Stream in PHP
但是,当我比较(与cksum一起使用)从命令行下载的zip和使用相同命令创建的zip时,结果不同。
这是我从PHP所做的事情:
<?php
$dir = "/path/to/myfolder";
$ficzip = basename($name) . ".zip";
header('Content-Transfer-Encoding: binary');
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . $ficzip. '"');
chdir( $dir );
$stream = popen( "/usr/bin/zip -qr -1 - .", "r" );
if( $stream )
{
fpassthru( $stream );
fclose( $stream );
}
?>
这是我从命令行执行的操作:
cd "/path/to/myfolder"
/usr/bin/zip -qr -1 - . > /tmp/myfolder.zip
我希望两个cksum都相同,但是不一样。 我想念什么?怎么做才能使它们相同?
编辑
这是两个文件的zipinfo之间的区别(在左侧下载的文件和右侧命令行文件)。
7,9c7,9
< Zip archive file size: 248145030 (000000000ECA6486h)
< Actual end-cent-dir record offset: 248145008 (000000000ECA6470h)
< Expected end-cent-dir record offset: 248145008 (000000000ECA6470h)
---
> Zip archive file size: 248144998 (000000000ECA6466h)
> Actual end-cent-dir record offset: 248144976 (000000000ECA6450h)
> Expected end-cent-dir record offset: 248144976 (000000000ECA6450h)
16c16
< is 248144779 (000000000ECA638Bh).
---
> is 248144747 (000000000ECA636Bh).
31c31
< compression sub-type (deflation): normal
---
> compression sub-type (deflation): fast
33c33
< extended local header: yes
---
> extended local header: no
59,60d58
< There are an extra 16 bytes preceding this file.
<
63,64c61,62
< offset of local header from start of archive: 248143809
< (000000000ECA5FC1h) bytes
---
> offset of local header from start of archive: 248143793
> (000000000ECA5FB1h) bytes
70c68
< compression sub-type (deflation): normal
---
> compression sub-type (deflation): fast
72c70
< extended local header: yes
---
> extended local header: no
EDIT2
将-1
替换为-Z store
进行不压缩,以减少差异,但仍然不行。
7,9c7,9
< Zip archive file size: 249693306 (000000000EE2047Ah)
< Actual end-cent-dir record offset: 249693284 (000000000EE20464h)
< Expected end-cent-dir record offset: 249693284 (000000000EE20464h)
---
> Zip archive file size: 249693274 (000000000EE2045Ah)
> Actual end-cent-dir record offset: 249693252 (000000000EE20444h)
> Expected end-cent-dir record offset: 249693252 (000000000EE20444h)
16c16
< is 249693055 (000000000EE2037Fh).
---
> is 249693023 (000000000EE2035Fh).
32c32
< extended local header: yes
---
> extended local header: no
58,59d57
< There are an extra 16 bytes preceding this file.
<
62,63c60,61
< offset of local header from start of archive: 249690256
< (000000000EE1F890h) bytes
---
> offset of local header from start of archive: 249690240
> (000000000EE1F880h) bytes
70c68
< extended local header: yes
---
> extended local header: no
解决方案
这是我用来获取相同结果的命令。我将问题悬而未决,以便有人可以解释命令popen和终端执行之间的区别。
/usr/bin/zip -qr -0 -fd -fz- - .