note 34919 added to function.stat
| From: | salisbm at hotmail dot com | Date: | Mon, 11 Aug 2003 22:21:00 +0000 |
| Subject: | note 34919 added to function.stat | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-53931@lists.php.net to get a copy of this message | ||
I was curious how I could tell if a file was a directory... so I found on http://www.hmug.org/man/2/stat.html the following
information about the mode bits:
#define S_IFMT 0170000 /* type of file */
#define S_IFIFO 0010000 /* named pipe (fifo) */
#define S_IFCHR 0020000 /* character special */
#define S_IFDIR 0040000 /* directory */
#define S_IFBLK 0060000 /* block special */
#define S_IFREG 0100000 /* regular */
#define S_IFLNK 0120000 /* symbolic link */
#define S_IFSOCK 0140000 /* socket */
#define S_IFWHT 0160000 /* whiteout */
#define S_ISUID 0004000 /* set user id on execution */
#define S_ISGID 0002000 /* set group id on execution */
#define S_ISVTX 0001000 /* save swapped text even after use */
#define S_IRUSR 0000400 /* read permission, owner */
#define S_IWUSR 0000200 /* write permission, owner */
#define S_IXUSR 0000100 /* execute/search permission, owner */
Note that these numbers are in octal format. Then, to check to see if the file is a directory,
after calling fstat, I do:
if ($fstats[mode] & 040000)
... this must be a directory
----
Manual Page -- http://www.php.net/manual/en/function.stat.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34919
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34919&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34919&report=yes