Ref/xattr-Phpdoc专题

xattr_get

Get an extended attribute

说明

string <span class="methodname">xattr_get ( <span class="type">string $filename , <span class="methodparam">string $name [, int $flags<span class="initializer"> = 0 ] )

This function gets the value of an extended attribute of a file.

扩展的属性有两种 不同的命名空间:user 和 root。user 命名空间对所有用户均有效,而 root 命名空间仅对拥有 root 权限的用户有效。 xattr 默认在 user 命名空间上操作,但可使用 flags 参数进行更改。

参数

filename
The file from which we get the attribute.

name
The name of the attribute.

flags
| | | |------------------------|----------------------------------------------------------------------| | XATTR_DONTFOLLOW | Do not follow the symbolic link but operate on symbolic link itself. | | XATTR_ROOT | Set attribute in root (trusted) namespace. Requires root privileges. |

返回值

Returns a string containing the value or false if the attribute doesn't exist.

范例

示例 #1 Checks if system administrator has signed the file

<?php
$file = '/usr/local/sbin/some_binary';
$signature = xattr_get($file, 'Root signature', XATTR_ROOT);

/* ... check if $signature is valid ... */

?>

参见

  • xattr_list
  • xattr_set
  • xattr_remove

xattr_list

Get a list of extended attributes

说明

array <span class="methodname">xattr_list ( <span class="type">string $filename [, <span class="methodparam">int $flags<span class="initializer"> = 0 ] )

This functions gets a list of names of extended attributes of a file.

扩展的属性有两种 不同的命名空间:user 和 root。user 命名空间对所有用户均有效,而 root 命名空间仅对拥有 root 权限的用户有效。 xattr 默认在 user 命名空间上操作,但可使用 flags 参数进行更改。

参数

filename
The path of the file.

flags
| | | |------------------------|----------------------------------------------------------------------| | XATTR_DONTFOLLOW | Do not follow the symbolic link but operate on symbolic link itself. | | XATTR_ROOT | Set attribute in root (trusted) namespace. Requires root privileges. |

返回值

This function returns an array with names of extended attributes.

范例

示例 #1 Prints names of all extended attributes of file

<?php
$file = 'some_file';
$root_attributes = xattr_list($file, XATTR_ROOT);
$user_attributes = xattr_list($file);

echo "Root attributes: \n";
foreach ($root_attributes as $attr_name) {
    printf("%s\n", $attr_name);
}

echo "\n User attributes: \n";
foreach ($attributes as $attr_name) {
    printf("%s\n", $attr_name);
}

?>

参见

  • xattr_get

xattr_remove

Remove an extended attribute

说明

bool <span class="methodname">xattr_remove ( <span class="methodparam">string $filename , string $name [, <span class="type">int $flags = 0 ] )

This function removes an extended attribute of a file.

扩展的属性有两种 不同的命名空间:user 和 root。user 命名空间对所有用户均有效,而 root 命名空间仅对拥有 root 权限的用户有效。 xattr 默认在 user 命名空间上操作,但可使用 flags 参数进行更改。

参数

filename
The file from which we remove the attribute.

name
The name of the attribute to remove.

flags
| | | |------------------------|----------------------------------------------------------------------| | XATTR_DONTFOLLOW | Do not follow the symbolic link but operate on symbolic link itself. | | XATTR_ROOT | Set attribute in root (trusted) namespace. Requires root privileges. |

返回值

成功时返回 true, 或者在失败时返回 false

范例

示例 #1 Removes all extended attributes of a file

<?php
$file = 'some_file';
$attributes = xattr_list($file);

foreach ($attributes as $attr_name) {
    xattr_remove($file, $attr_name);
}
?>

参见

  • xattr_list
  • xattr_set
  • xattr_get

xattr_set

Set an extended attribute

说明

bool <span class="methodname">xattr_set ( <span class="type">string $filename , <span class="methodparam">string $name , string $value [, <span class="type">int $flags = 0 ] )

This function sets the value of an extended attribute of a file.

扩展的属性有两种 不同的命名空间:user 和 root。user 命名空间对所有用户均有效,而 root 命名空间仅对拥有 root 权限的用户有效。 xattr 默认在 user 命名空间上操作,但可使用 flags 参数进行更改。

参数

filename
The file in which we set the attribute.

name
The name of the extended attribute. This attribute will be created if it doesn't exist or replaced otherwise. You can change this behaviour by using the flags parameter.

value
The value of the attribute.

flags
| | | |------------------------|----------------------------------------------------------------------| | XATTR_CREATE | Function will fail if extended attribute already exists. | | XATTR_REPLACE | Function will fail if extended attribute doesn't exist. | | XATTR_DONTFOLLOW | Do not follow the symbolic link but operate on symbolic link itself. | | XATTR_ROOT | Set attribute in root (trusted) namespace. Requires root privileges. |

返回值

成功时返回 true, 或者在失败时返回 false

范例

示例 #1 Sets extended attributes on .wav file

<?php
$file = 'my_favourite_song.wav';
xattr_set($file, 'Artist', 'Someone');
xattr_set($file, 'My ranking', 'Good');
xattr_set($file, 'Listen count', '34');

/* ... other code ... */

printf("You've played this song %d times", xattr_get($file, 'Listen count')); 
?>

参见

  • xattr_get
  • xattr_remove

xattr_supported

Check if filesystem supports extended attributes

说明

bool <span class="methodname">xattr_supported ( <span class="methodparam">string $filename [, int $flags = 0 ] )

This functions checks if the filesystem holding the given file supports extended attributes. Read access to the file is required.

参数

filename
The path of the tested file.

flags
| | | |------------------------|----------------------------------------------------------------------| | XATTR_DONTFOLLOW | Do not follow the symbolic link but operate on symbolic link itself. |

返回值

This function returns true if filesystem supports extended attributes, false if it doesn't and null if it can't be determined (for example wrong path or lack of permissions to file).

范例

示例 #1 xattr_supported example

The following code checks if we can use extended attributes.

<?php
$file = 'some_file';

if (xattr_supported($file)) {
    /* ... make use of some xattr_* functions ... */
}

?>

参见

  • xattr_get
  • xattr_list

目录


本站为非盈利网站,作品由网友提供上传,如无意中有侵犯您的版权,请联系删除