【发布时间】:2016-07-17 04:48:53
【问题描述】:
当我使用 PHP ZipArchive 对象制作 ZIP 存档时,存档中的所有文件都将权限设置为 666,尽管原始文件的权限设置为 644。
我的脚本正确地制作了 zip 存档,只是权限混乱了。
////// 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();
附:我在 Mac 上使用 MAMP。我刚刚发现只有在选择 PHP 5.6.10 版本时才会出现这个问题。当我选择5.5.26时,文件的权限是正确的。
【问题讨论】: