Re note posted by "salisbm at hotmail dot com":
S_IFDIR is not a single-bit flag. It is a constant that relies on the "S_IFMT" bitmask. This bitmask should be applied to the "mode" parameter before comparing with any of the other "S_IF..." constants, as indicated by stat.h:
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
That is, this approach is incorrect:
<?php
define('S_IFDIR',040000);
if ($mode & S_IFDIR)
{
}
?>
...and should instead be:
<?php
define('S_IFMT',0170000);
define('S_IFDIR',040000);
if (S_IFDIR == ($mode & S_IFMT)) { }
?>
As pointed out by "svend at svendtofte dot com", however, there is also the "is_dir" function for this purpose, along with "is_file" and "is_link" to cover the most common format types...