2024 年日本 PHP 研討會

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

如果 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";
}
?>
新增註解

使用者提供的註解

此頁面沒有使用者提供的註解。
To Top