Php 为什么使用数据创建的ZIP归档文件没有压缩?

Php 为什么使用数据创建的ZIP归档文件没有压缩?,php,zip,Php,Zip,我尝试使用PharData,因为它似乎提供了一种创建ZIP或tar归档的好方法。不幸的是,以这种方式创建的ZIP存档似乎根本没有压缩: /tmp# ls -lah total 2.3M drwxrwxrwt 5 root root 4.0K Sep 16 14:54 . drwxr-xr-x 82 root root 4.0K Sep 16 14:54 .. -rw------- 1 www-data 1000 2.3M Sep 2 16:46 test.csv /tmp#

我尝试使用PharData,因为它似乎提供了一种创建ZIP或tar归档的好方法。不幸的是,以这种方式创建的ZIP存档似乎根本没有压缩:

/tmp# ls -lah
total 2.3M
drwxrwxrwt  5 root     root 4.0K Sep 16 14:54 .
drwxr-xr-x 82 root     root 4.0K Sep 16 14:54 ..
-rw-------  1 www-data 1000 2.3M Sep  2 16:46 test.csv
/tmp# php -a
Interactive shell

php > $a = new PharData('/tmp/test.zip', null, null, Phar::ZIP);
php > $a->addFile('/tmp/test.csv');
php > exit
/tmp# ls -lah
total 4.6M
drwxrwxrwt  5 root     root 4.0K Sep 16 14:56 .
drwxr-xr-x 82 root     root 4.0K Sep 16 14:54 ..
-rw-------  1 www-data 1000 2.3M Sep  2 16:46 test.csv
-rw-r--r--  1 root     root 2.3M Sep 16 14:56 test.zip
test.csv具有高度可压缩的csv数据。压缩文件应该有大约500KB


那么这里的问题是什么?

如果要创建zip文件,请使用ZipArchive。。。。这是进行SOB的标准工具,但在回答您的问题时,请使用compress或CompressFiles方法,我知道,我可以使用ZipArchive。但这不是问题所在。@MarkBaker好的,compressFiles是丢失的部分。compress在这里会抛出一个错误,因为它只适用于Phar::TAR文件。谢谢