note 27895 added to function.is-dir
| From: | tech at appideas dot com | Date: | Mon, 23 Dec 2002 19:55:47 +0000 |
| Subject: | note 27895 added to function.is-dir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41232@lists.php.net to get a copy of this message | ||
The comment above (Dec 18, 2002) is not entirely correct.
is_file() will also return false if the file does not exist. A better test would be to wrap the
is_file() test in a file_exists() test:
if( file_exists( $dir ) )
{
if( !is_file( $dir ) )
{
// this is a directory, do something
}
}
Or a little more compact, but a little less clear way of doing the same thing:
if( file_exists( $dir ) && !is_file( $dir ) )
{
// this is a directory, do something
}
The other comment would return that $dir is a directory if the file/dir is not found - probably not
what you want in your production code. :-)
--
http://www.php.net/manual/en/function.is-dir.php
http://master.php.net/manage/user-notes.php?action=edit+27895
http://master.php.net/manage/user-notes.php?action=delete+27895
http://master.php.net/manage/user-notes.php?action=reject+27895