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.