It used to be. NET, and because of the open source issue, I recently started to learn PHP.
Due to the long-term use of the computer under Linux, so specially to make the environment into a fedora20+apache+php+mysql.
Because it is not a big coffee, the whole environment uses Yum installation. All the way smoothly.
Currently learning to PHP multi-File Download this chapter, the road ahead is still smooth, but to this chapter, too bad. The first thing to consider is that the ziparchive needs to be extended, but because it is a yum installation, I don't know if this extension is installed. Daoteng a long time to find out, in fact, yum installation has installed this extension for me, but finally proved that the Yum installation has installed this extension for me, and this extension in phpinfo corresponding to the zip module.
Gossip doesn't say much, tell me about the problems I have today, the code is as follows:
while (true) {$archiveName = MD5 (Uniqid (). Time ()). ". Zip "; if (!file_exists ("./". $archiveName)) break; } $zip = new ziparchive ();//Depending on the file name, open a zip archive, if the package does not exist, then create a ziparchive::overwrite//the mode opened here is not available under Linux Ziparchive::o Verwrite from Create Zip package if (! $zip->open ($archiveName, ziparchive::create)) {die ("Open compression package Failed");} foreach ($files as $v) {$zip->addfile ($v); }//the file into the ziparchive to close the zip package, otherwise it will be downloaded to an empty package $zip->close ();
Repeated testing, but is unable to generate the correct ZIP package, error message: Ziparchive::addfile (): Invalid or Uninitialed object in ....
Originally thought to be the problem of the Zip module, but later found that the $zip object is instantiated successfully. That should not be a module problem.
Later, after each $zip->open (), my server did not produce the corresponding ZIP package. It's early morning, Dizzy.
Woke up refreshed. So try to change the demo. Finally, it was discovered that, in the Linux environment,
Do not use Ziparchive::overwrite to create zip packages, small problems, delayed for a long time. I hope this problem can help the friends who meet the same problem. Finally, I would like to thank the twin teacher who has been helping in the course of learning.
Linux Ziparchive finally working.