Home > Article > Backend Development > How to implement if in php to determine whether a folder exists
php method to implement if to determine whether a folder exists: first create a PHP sample file; then determine whether the folder exists through the "if (!mkdirs(dirname($dir), $mode))" method, If it does not exist, just create it.
Recommendation: "PHP Video Tutorial"
The operating environment of this tutorial: Windows 7 system, PHP version 5.6, This method works for all brands of computers.
php determines whether the folder exists, and creates it if it does not exist
function mkdirs($dir, $mode = 0777) { if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE; if (!mkdirs(dirname($dir), $mode)) return FALSE; return @mkdir($dir, $mode); }
mkdirs("aa01");
The default mode is 0777, which means the maximum possibility access rights. For more information about mode please read the chmod() page.
The above is the detailed content of How to implement if in php to determine whether a folder exists. For more information, please follow other related articles on the PHP Chinese website!