Home > Backend Development > PHP Tutorial > Use of php ZipArchive class

Use of php ZipArchive class

WBOY
Release: 2016-10-22 00:14:13
Original
1184 people have browsed it

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>
Copy after login
Copy after login

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?

Reply content:

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>
Copy after login
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template