Linux Ziparchive finally working.

Source: Internet
Author: User
Tags create zip learn php ziparchive

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.