php is_dir() function introduction
is_dir — Determine whether the given file name is a directory
Syntax: (Recommended learning: PHP Programming from entry to proficiency)
bool is_dir ( string $filename )
Determine whether the given file name is a directory.
Parameters:
filename Returns TRUE if the file name exists and is a directory. If filename is a relative path, its relative path is checked against the current working directory.
Return value:
If the file name exists and is a directory, return TRUE, otherwise return FALSE.
php is_dir() example
/** * 判断 文件/目录 是否可写(取代系统自带的 is_writeable 函数) * * @param string $file 文件/目录 * @return boolean */ function new_is_writeable($file) { if (is_dir($file)){ $dir = $file; if ($fp = @fopen("$dir/test.txt", 'w')) { @fclose($fp); @unlink("$dir/test.txt"); $writeable = 1; } else { $writeable = 0; } } else { if ($fp = @fopen($file, 'a+')) { @fclose($fp); $writeable = 1; } else { $writeable = 0; } } return $writeable; }
The above is the detailed content of PHP function to determine whether it is a directory. For more information, please follow other related articles on the PHP Chinese website!