函数名:xattr_list()
适用版本:PHP 5 >= 5.3.0, PHP 7
函数描述:xattr_list() 函数用于获取指定文件或目录的扩展属性列表。
语法:array xattr_list ( string $filename [, int $flags = 0 ] )
参数:
返回值:返回一个包含扩展属性名称的数组,如果出错则返回 FALSE。
示例:
// 获取文件的扩展属性列表
$file = '/path/to/file.txt';
$attributes = xattr_list($file);
if ($attributes !== false) {
echo "文件 {$file} 的扩展属性列表:\n";
foreach ($attributes as $attribute) {
echo "- {$attribute}\n";
}
} else {
echo "获取扩展属性列表失败。\n";
}
// 获取目录的扩展属性列表(不跟随符号链接)
$dir = '/path/to/directory';
$attributes = xattr_list($dir, XATTR_NOFOLLOW);
if ($attributes !== false) {
echo "目录 {$dir} 的扩展属性列表:\n";
foreach ($attributes as $attribute) {
echo "- {$attribute}\n";
}
} else {
echo "获取扩展属性列表失败。\n";
}
注意事项:
php_xattr.dll 扩展模块才能使用扩展属性功能。