本文整理汇总了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