[ACCEPTED]-Check whether a directory exists in PHP-file-io
Should work correctly. From is_dir()
documentation:
Returns 4 TRUE if the filename exists and is a directory, FALSE otherwise.
Well, anyway 3 if it doesn't try this:
if(file_exists($dir) && is_dir($dir))
BTW. results of these 2 functions are cached in stat cache. Use 1 clearstatcache() to clean that cache.
You'll probably want to use opendir() after is_dir() agrees 9 that the path (could) be a directory.
If 8 the resource returned by opendir() is valid, you 7 know you have a directory, and already have 6 a handle to read it.
Just be sure to call 5 closedir(), either way, if a valid handle 4 is returned.
Edit:
This answer assumes that 3 you'll be opening the directory either way. If 2 you just need to ensure a path is sane / valid, file_exists() is 1 much cheaper.
bool file_exists ( string $filename )
Checks whether a file or directory exists.
http://php.net/manual/en/function.file-exists.php
0
You could try this:
if(is_dir($dir) && is_writeable($dir))
{
// ...
}
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.