I am using php ZipArchive to create a zip directory file. The code works fine for almost all directories except the two which are the largest (the largest directory currently contains 51 files with a total capacity of 175 MB). When I run the code for these directories, a temporary file ('filename.zip. [RandomLettersAndNumbers]', for example 'filename.zip.riaab4') will be created with a size of 67 108864 bytes, and the script will generate an internal server error (500).
What I have tried so far (most of them are still visible in the source):
- Increase
memory_limit - Increase
max_execution_time - Check php error log: error log is empty
- Try to find the exact line where the error occurs: the code runs until
$zip_archive->close();
A source:
//Temporary (debugging) START ini_set("log_errors", 1); ini_set("error_log", "php-error.log"); error_log("Hello errors."); ini_set('memory_limit','512M'); set_time_limit(180); //phpinfo(); //Temporary (debugging) END //Get selected directory // --> Code removed $result['directory'] = 'directory1'; //Create .zip file $zip_archive = new ZipArchive(); $ZIP = 'files/'.$result['directory'].'.zip'; if($zip_archive->open($ZIP, ZipArchive::CREATE | ZIPARCHIVE::OVERWRITE) !== TRUE) { echo 'Error! Error while creating ZIP Archive.'; die; } foreach(new DirectoryIterator('files/'.$result['directory']) as $fileInfo) { if($fileInfo->isDot()) continue; if(file_exists($fileInfo->getPath())) $zip_archive->addFile('files/'.$result['directory'].'/'.$fileInfo->getFilename(), $fileInfo->getFilename()); } //Temporary (debugging) START echo '<br><br><br>'; var_dump($zip_archive->close()); //
Am I missing something? If there is anything else I can try, please let me know. Thanks.
EDIT: I have a more specific question: why do temporary zip files from affected directories have a file size of 67 108 864 bytes? Is this related to the maximum file size set by php / server, or can this be explained by the zip standard / ZipArchive?
source share