downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

lstat> <link
[edit] Last updated: Fri, 25 May 2012

view this page in

linkinfo

(PHP 4, PHP 5)

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

説明

int linkinfo ( string $path )

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

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

パラメータ

path

リンクへのパス。

返り値

linkinfo()は、lstat システムコールで返された Unix C 言語の stat 構造体の st_dev フィールドを返します。 0 を返し、エラーの場合に FALSE を返します。

変更履歴

バージョン 説明
5.3.0 この関数は、Windows プラットフォーム (Vista 以降、あるいは Server 2008 以降) でも動作するようになりました。

例1 linkinfo() の例

<?php

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

?>

参考

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



add a note add a note User Contributed Notes linkinfo
rjb at robertjbrown dot com 21-Feb-2012 01:14
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.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites