faqts : Computers : Programming : Languages : PHP : Common Problems : Files

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

69 of 73 people (95%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

How do you check if a directory exists? if(opendir("./xxxx")) just returns an error.

Jan 24th, 2001 22:35
Mike Boucher, Brock Sperryn, http://www.php.net/manual/en/function.is-dir.php


is_dir checks to see if $dirname exists and is a directory. If it does 
exist and it is a directory then it returns 'true', otherwise it 
returns 'false'. So you can use it as follows.
if(is_dir($dirname))
{
   echo "Yes, the directory ".$dirname." exists.";
}
else
{
   echo $dirname." is not a valid directory.";
}
See http://www.php.net/manual/en/function.is-dir.php for more 
information.
More information on directory and file functions can be found at:
directory functions:
http://www.php.net/manual/en/ref.dir.php
filesystem funtions (and some more directory functions):
http://www.php.net/manual/en/ref.filesystem.php
Hope this helps