PHP8 ZipArchive::getExternalAttributesIndex

2024-02-26 14:05 更新

(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

檢索由其索引定義的條目的外部屬性。

參數(shù) 

index

條目的索引。

opsys

成功后,接收由 ZipArchive::OPSYS_ 常量之一定義的操作系統(tǒng)代碼。

attr

成功后,接收外部屬性。值取決于操作系統(tǒng)。

flags

如果 flags 設(shè)置為 ZipArchive::FL_UNCHANGED,則原始保持不變 返回屬性。

返回值 

成功時返回 true, 或者在失敗時返回 false。

示例 

本示例提取 ZIP 的所有條目 archive 和 從外部屬性設(shè)置 Unix 權(quán)限。test.zip

示例 #1 提取所有具有 Unix 權(quán)限的條目

<?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";
}
?>


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號