Search code examples
phpzipphp-ziparchive

php ZipArchive addfile not work


Here's my code

<?php
error_reporting(-1);
ini_set('memory_limit','1G');

$zip = new ZipArchive();
if ($zip->open(__DIR__.'/xxx.zip') === TRUE) {
        echo __DIR__.'/CPInfo.txt'."\n";
        $zip->addFile(__DIR__.'/CPInfo.txt', 'newname.txt');        
        $x =  $zip->close();
        var_dump($x);
        echo 'ok';
} else {
        echo 'failed';
}
?>

I have run command

[root@localhost]# php test.php 

And the output is

/data/yyy/CPInfo.txt
bool(true)
ok

No errors are given while adding the txt into the .zip. When I open xxx.zip, nothing is changed. File xxx.zip contains more than 1000 files and 100 folders

When i remove 900 files from xxx.zip and run this script again, it's work.

What am I doing wrong?

file open limit

ulimit -a

output

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 514831
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 99999
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 500000
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

php version

PHP 5.5.13 (cli) (built: Jun  3 2014 13:27:36) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

Solution

  • I'm downgrade from php55 to php54 and everything work well.