Use of the phpZipArchive class

Source: Internet
Author: User
Tags ziparchive
This is the case: Prepare for batch download, put all the resources to be downloaded in the compressed package, and use the ZipArchive class code: {code ...} but the problem arises. 1. you must add a file to the zip file to open the file. in my personal opinion, if the zip file is empty, the system will not create the zip file ,... this is the case: Prepare for batch download, put all the resources to be downloaded in the compressed package, and use the ZipArchive class.

Code:

$filename='test.zip';$zip=new ZipArchive();$zip->open($filename,ZipArchive::CREATE);$zip->addFile('favicon.ico');$zip->close();var_dump(fopen($filename,'r'));var_dump(filesize($filename));

But the problem arises.
1. you must add a file to the zip file to open the zip file. in my personal opinion, if the zip file is empty, the system will not create the zip file, and the zip file is not actually created. Is that true?
2. in my test, fopen or filesize is required after $ zip-> close (). the parameter is $ filename. why?
3. after testing, the fopen or filesize parameter cannot be $ zip-> filename. why?

Reply content:

This is the case: Prepare for batch download, put all the resources to be downloaded in the compressed package, and use the ZipArchive class.

Code:

$filename='test.zip';$zip=new ZipArchive();$zip->open($filename,ZipArchive::CREATE);$zip->addFile('favicon.ico');$zip->close();var_dump(fopen($filename,'r'));var_dump(filesize($filename));

But the problem arises.
1. you must add a file to the zip file to open the zip file. in my personal opinion, if the zip file is empty, the system will not create the zip file, and the zip file is not actually created. Is that true?
2. in my test, fopen or filesize is required after $ zip-> close (). the parameter is $ filename. why?
3. after testing, the fopen or filesize parameter cannot be $ zip-> filename. why?

Before executing $ zip-> addFile, first determine whether the file to be compressed exists.
$ Zip-> close can no longer use $ zip, so $ zip-> filename cannot be used.

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.