Home > Article > Backend Development > Use of php ZipArchive class
The thing is like this: Prepare to do a batch download, put all the resources that need to be downloaded in a compressed package, and use the ZipArchive class
Code:
<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)); </code>
But here comes the problem
1. You must add files to the zip before it can be opened correctly. My personal understanding is that if the zip is empty, the system will not create the zip. In fact, it is not created. Is that so?
2. My test is to fopen or filesize after $zip->close(). The parameter is $filename. Why?
3. After testing, the parameter of fopen or filesize cannot be $zip->filename. Why?
The thing is like this: prepare to do a batch download, put all the resources that need to be downloaded in a compressed package, and use the ZipArchive class
Code:
<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)); </code>
But here comes the problem
1. You must add files to the zip before it can be opened correctly. My personal understanding is that if the zip is empty, the system will not create the zip. In fact, it is not created. Is that so?
2. My test is to fopen or filesize after $zip->close(). The parameter is $filename. Why?
3. After testing, the parameter of fopen or filesize cannot be $zip->filename. Why?
Before executing $zip->addFile, first determine whether the file to be compressed exists.
After $zip->close, $zip can no longer be used, so $zip->filename cannot be used.