PHP 8.3.4 Released!

fileowner

(PHP 4, PHP 5, PHP 7, PHP 8)

fileownerファイルの所有者を取得する

説明

fileowner(string $filename): int|false

ファイルの所有者を取得します。

パラメータ

filename

ファイルへのパス。

戻り値

ファイルの所有者のユーザー ID を返し、失敗した場合に false を返します。 ユーザー ID は数値で返されます。ユーザー名に変換するには posix_getpwuid() を使用してください。

エラー / 例外

失敗したときは E_WARNING が発生します。

例1 ファイルの所有者の取得

<?php
$filename
= 'index.php';
print_r(posix_getpwuid(fileowner($filename)));
?>

注意

注意: この関数の結果は キャッシュされます。詳細は、clearstatcache() を参照してください。

ヒント

PHP 5.0.0 以降、この関数は、 何らかの URL ラッパーと組合せて使用することができます。 どのラッパーが stat() ファミリーをサポートしているかを調べるには サポートするプロトコル/ラッパー を参照してください。

参考

  • filegroup() - ファイルのグループを取得する
  • stat() - ファイルに関する情報を取得する
  • posix_getpwuid() - 指定 ID のユーザーに関する情報を返す

add a note

User Contributed Notes 3 notes

up
12
dazoe
13 years ago
Remember to use if(fileowner(...) === FALSE) instead of if(!fileowner()) or if(fileowner() == FLASE) because if the owner was "root" it would return 0.
up
9
Anonymous
18 years ago
Small note: the function resolves symbolic links. That is, if the link is created by user 999 and maps to a file owned by user 666, this function returns 666 :(
up
7
chris at ocproducts dot com
4 years ago
This function will always return 0 on Windows, because Windows does not support numeric user IDs.
To Top