I'm trying to create three zip packages with php. I'm running a function that copies a directory and looking through the content to add each file with a loop into the zip.
Problem is that ZipArchive does not seem to close the files when finishing up. What I want to end up with is three zip files like this:
Package1.zip
Package2.zip
Package3.zip
Instead I end up with something like this:
Package1.zip.a012341
Package1.zip.b012342
Package2.zip.a023451
Package2.zip.b023452
Package3.zip.a034561
Package3.zip.b034562
It's like the zip files don't close and finish up to remove the temporary extension and tries to create another one of each file and fails with those aswell. I get no error what so ever, atleast not what I've seen.
What I'm guessing is that there are some kind of setting I need to change in php.ini or on my webserver/IIS. The files I'm trying to create are pretty big, somewhere between 450 - 600 MB.
This is my best guess because I got two almost identical server setups I've tried the same code on. It works perfectly on one of them but not the other. That proves that my ZipArchive code can not the issue here (I did not set up the servers btw, so I'm not sure what differs).
I've tried to increase the memory_limit and execution time in my php.ini. The latter was an earlier issue and I got a message telling me it had timed out.
Thanks in advance!
Edit: Added the function.
function package_site($filepath, &$context) {
$context['message'] = 'Creating package';
// Mac app
$mac_zipfile = 'public://site_export/mac_package.zip';
copy_directory($mac_zipfile, $filepath . '/mac_package.zip', '/.*/');
$files = file_scan_directory($filepath . '/files', '/.*/');
$mac_zip = new ZipArchive();
if($mac_zip->open(drupal_realpath($filepath . '/mac_package.zip')) === true) {
foreach($files as $key => $value) {
$mac_zip->addFile(drupal_realpath($value->uri), 'mac_package.app/Contents/Resources/' . substr(drupal_realpath($value->uri), strlen(drupal_realpath($filepath . '/files')) + 1));
}
} else {
drupal_set_message("Could NOT open mac_package.zip");
}
$mac_zip->close();
// PC app
drupal_unlink($filepath . '/package.zip');
$start_files_path_pc = 'public://site_export/pc_files';
copy_directory($start_files_path_pc, $filepath . '/files', '/.*/');
$pc_files = file_scan_directory($filepath . '/files', '/.*/');
$zip = new ZipArchive();
$res = $zip->open(drupal_realpath($filepath . '/package.zip'), ZipArchive::CREATE);
if ($res === TRUE) {
foreach ($pc_files as $key => $value) {
$zip->addFile(drupal_realpath($value->uri), substr(drupal_realpath($value->uri), strlen(drupal_realpath($filepath . '/files')) + 1));
}
$zip->close();
}
// Create a html package
create_pure_html_package($filepath);
// HTML package
drupal_unlink($filepath . '/html.zip');
$html_files = file_scan_directory($filepath . '/files/site', '/.*/');
$zip_html = new ZipArchive();
$res = $zip_html->open(drupal_realpath($filepath . '/html.zip'), ZipArchive::CREATE);
if ($res === TRUE) {
foreach ($html_files as $key => $value) {
$zip_html->addFile(drupal_realpath($value->uri), substr(drupal_realpath($value->uri), strlen(drupal_realpath($filepath . '/files')) + 1));
}
$zip_html->addFile(drupal_realpath($filepath . '/start.html'), 'start.html');
$zip_html->close();
}
rrmdir(drupal_realpath($filepath . '/files'));
unlink(drupal_realpath($filepath . '/start.html'));
}