本文整理匯總了PHP中ZipArchive::setExternalAttributesName方法的典型用法代碼示例。如果您正苦於以下問題:PHP ZipArchive::setExternalAttributesName方法的具體用法?PHP ZipArchive::setExternalAttributesName怎麽用?PHP ZipArchive::setExternalAttributesName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ZipArchive
的用法示例。
在下文中一共展示了ZipArchive::setExternalAttributesName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: packageZip
function packageZip($name, $path)
{
$zip = new ZipArchive();
if (!$zip->open($name, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true) {
return false;
}
$php56 = version_compare(phpversion(), '5.6.0', '>');
$addFiles = function ($dir) use(&$addFiles, $zip, $path, $php56) {
$files = array_diff(scandir($dir), array('.', '..'));
$path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
foreach ($files as $file) {
$full = "{$dir}/{$file}";
$local = str_replace($path, '', $full);
if (is_dir($full)) {
$addFiles($full);
} else {
// XXX: AddFile() will keep the file open and run
// out of OS open file handles
$zip->addFromString($local, file_get_contents($full));
}
// This only works on PHP >= v5.6
if ($php56) {
// Set the Unix mode of the file
$stat = stat($full);
$zip->setExternalAttributesName($local, ZipArchive::OPSYS_UNIX, $stat['mode']);
}
}
};
$addFiles($path);
return $zip->close();
}
示例2: ZipArchive
<?php
$name = __DIR__ . '/withattr.zip';
echo "== Set\n";
$zip = new ZipArchive();
$r = $zip->open($name, ZIPARCHIVE::CREATE);
$zip->addFromString('foo.txt', 'foo');
$zip->addFromString('bar.txt', 'bar');
var_dump($zip->setExternalAttributesName('foo.txt', ZipArchive::OPSYS_UNIX, 123));
$id = $zip->locateName('bar.txt');
var_dump($zip->setExternalAttributesIndex($id, ZipArchive::OPSYS_VFAT, 234));
$zip->close();
echo "== Get\n";
$r = $zip->open($name);
var_dump($zip->getExternalAttributesName('foo.txt', $a, $b), $a, $b);
$id = $zip->locateName('bar.txt');
var_dump($zip->getExternalAttributesIndex($id, $a, $b), $a, $b);
echo "== Set\n";
var_dump($zip->setExternalAttributesName('foo.txt', ZipArchive::OPSYS_DOS, 345));
var_dump($zip->setExternalAttributesIndex($id, ZipArchive::OPSYS_AMIGA, 456));
echo "== Get changed\n";
var_dump($zip->getExternalAttributesName('foo.txt', $a, $b), $a, $b);
var_dump($zip->getExternalAttributesIndex($id, $a, $b), $a, $b);
echo "== Get unchanged\n";
var_dump($zip->getExternalAttributesName('foo.txt', $a, $b, ZipArchive::FL_UNCHANGED), $a, $b);
var_dump($zip->getExternalAttributesIndex($id, $a, $b, ZipArchive::FL_UNCHANGED), $a, $b);
$zip->close();
?>
== Done