When I make ZIP archive using PHP ZipArchive object, all files inside the archive have permissions set to 666, although original files have permissions set to 644.
My script makes the zip archives properly, just the permissions are messed up.
////// Make Template archive object
$templateArchive = new ZipArchive();
$templateArchive->open(PATH_TO_TEMPLATES.'_files/'.$templateName.'/_pack/'.$templateName.'.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($templateDir."/templates/".$template_archive_name),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
// Skip directories (they would be added automatically)
if (!$file->isDir())
{
// Get real and relative path for current file
$filePath = $file->getRealPath();
// relative path is full path, reduced with length of templateDir string and 11 more chars for /templates/
$relativePath = substr($filePath, strlen($templateDir) + 11);
// Add current file to archive
$templateArchive->addFile($filePath, $relativePath);
}
}
// Template Zip archive will be created only after closing object
$templateArchive->close();
P.S. I am working of MAMP on Mac. I just found out that issue is only when PHP 5.6.10 version is selected. When I select 5.5.26, the permissions of files are correct.