I'm using phps ZipArchive class to create a zip file of a directory. The code works fine for almost all directories except two, which happen to be the largest ones (the largest directory currently contains 51 files with a total of 175MB). When I'm running the code for these directories a temporary file ('filename.zip.[RandomLettersAndNumbers]', e.g. 'filename.zip.riaab4') will be created with a size of 67,108,864 bytes and the script throws an internal server error (500).
What I've tried so far (most of it is still visible in the source):
- Increase
memory_limit
- Increase
max_execution_time
- Check the php error log: error log is empty
- Try to find the exact line where the error occurs: the code is executed up to
$zip_archive->close();
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());
// ## The following lines are not executed!! ##
echo '<br><br><br>';
var_dump($zip_archive->getStatusString());
echo '<br><br><br>';
//Temporary (debugging) END
if($zip_archive->numFiles > 0 && $zip_archive->close() == true)
$FILE = $ZIP;
else {
}
Am I missing something? If there's anything else I can try please let me know. Thanks.
EDIT: I've got a more specific question: Why do the temporary zip files of the affected directories all have a file size of 67,108,864 bytes? Is this related to a maximum file size set by php/the server or can this be explained with the zip standard/ZipArchive class?