是否有任何函数来检查PHP中是否存在目录或文件夹?

I want to check if there is a directory exist or not before uploading a file.

If the directory does not exist return FALSE.

Does is_dir do the work?

is_dir() well check if the first argument is a directory and is_file() will check if the first argument is a file.

They both return true if the dir/file exists, and false if not.

Yes is_dir() is the solution. Did you try it?

For example, if you wanted to check that "etc/data/images/" is a directory you could use:

$dir = "etc/data/images/";  //First specify the directory you want to check existence of.

    if(is_dir($dir)){ //The 'is_dir' function does the checking.

     echo "Yes, $dir is a directory.";

}else{//If 'is_dir' returns false, the following will be ran:

    echo 'No that is not a directory...';
}