PHP Velho Oeste 2024

linkinfo

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

linkinfoリンクに関する情報を取得する

説明

linkinfo(string $path): int|false

リンクに関する情報を取得します。

この関数を使用して (pathが指している) リンクが実際に存在するかどうかを、 (stat.h で定義されている S_ISLNK マクロと同じ方法で) チェックします。

パラメータ

path

リンクへのパス。

戻り値

linkinfo()は、lstat システムコールで返された Unix C 言語の stat 構造体の st_dev フィールドを返します。 成功した場合は負でない数値を返します。 リンクが存在しない場合は -1 を返し、open.base_dir の違反が起きた場合は false を返します。

例1 linkinfo() の例

<?php

echo linkinfo('/vmlinuz'); // 835

?>

参考

  • symlink() - シンボリックリンクを作成する
  • link() - ハードリンクを作成する
  • readlink() - シンボリックリンク先を返す

add a note add a note

User Contributed Notes 1 note

up
1
rjb at robertjbrown dot com
12 years ago
I expected this function to return FALSE or 0 if a symbolic link did not exist (per the documentation above), but that's not what happened. Reading the man page for the Linux kerne's stat call here: http://www.kernel.org/doc/man-pages/online/pages/man2/stat.2.html it says this:

RETURN VALUE - On success, zero is returned.  On error, -1 is returned, and errno is set appropriately.

... which is what is happening in my case. I am doing a linkinfo('/path/to/file'); on a missing symlink, and I get back a value of -1. As we know, a value of -1 is not going to evaluate to a FALSE or 0.

My point - be careful with return values for missing symlinks.
To Top