CakeFest 2024: The Official CakePHP Conference

ZipArchive::getExternalAttributesIndex

(PHP 5 >= 5.6.0, PHP 7, PHP 8, PECL zip >= 1.12.4)

ZipArchive::getExternalAttributesIndexインデックスで定義されたエントリの外部属性を取得する

説明

public ZipArchive::getExternalAttributesIndex(
    int $index,
    int &$opsys,
    int &$attr,
    int $flags = 0
): bool

インデックスで定義されたエントリの外部属性を取得します。

パラメータ

index

エントリのインデックス

opsys

成功した場合に、 ZipArchive::OPSYS_ 定数のうちのひとつで定義された、 オペレーティングシステムコードを取得します。

attr

成功した場合に、外部属性を取得します。 値はオペレーティングシステム依存です。

flags

ZipArchive::FL_UNCHANGED に設定された場合、 オリジナルの変更されなかった属性が返されます。

戻り値

成功した場合に true を、失敗した場合に false を返します。

この例は、ZIP アーカイブ test.zip の 全エントリを展開し、外部属性から Unixの権限を設定しています。

例1 全てのエントリをUnixの権限付きで展開する

<?php
$zip
= new ZipArchive();
if (
$zip->open('test.zip') === TRUE) {
for (
$idx=0 ; $s = $zip->statIndex($idx) ; $idx++) {
if (
$zip->extractTo('.', $s['name'])) {
if (
$zip->getExternalAttributesIndex($idx, $opsys, $attr)
&&
$opsys==ZipArchive::OPSYS_UNIX) {
chmod($s['name'], ($attr >> 16) & 0777);
}
}
}
$zip->close();
echo
"Ok\n";
} else {
echo
"KO\n";
}
?>
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top