note 20492 added to function.stat
| From: | ashley at dcs dot warwick dot ac dot uk | Date: | Fri, 05 Apr 2002 11:10:40 +0000 |
| Subject: | note 20492 added to function.stat | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-28653@lists.php.net to get a copy of this message | ||
I think "3. inode protection mode" is incorrect. Value 2 in the array actually seems to
actually correspond to st_mode from a C stat() call, ie what the UNIX man pages call file
"mode", or what I would call "file type".
At the moment, I'm trying to reliably detect files that are not regular files or directories.
I don't seem to be able to do this with is_file and is_dir (this seems to mess up on special
files, eg named pipes).
What I have constructed below seems to do what I want, but careful if you want to reuse it: it
isn't well tested yet and the constant values are from a system file on Solaris 8.
// from /usr/include/sys/stat.h -- careful: probably only valid on Solaris
define("S_IFMT", 0xF000);
define("S_IFREG", 0x8000);
define("S_IFDIR", 0x4000);
if ((s = lstat($fileName)) == false)
die("ERROR: failed to stat file $fileName");
$type = s[2] & S_IFMT;
if (($type != S_IFREG) && ($type != S_IFDIR))
die("ERROR: expecting file or directory and found something else at $fileName");
--
http://www.php.net/manual/en/function.stat.php
http://master.php.net/manage/user-notes.php?action=edit+20492
http://master.php.net/manage/user-notes.php?action=delete+20492
http://master.php.net/manage/user-notes.php?action=reject+20492