Home>Article>Backend Development> How to create a php directory if it does not exist
The implementation method of creating a php directory if it does not exist: first define a "mkdirs" method; then use the if statement to determine whether the directory exists; finally create the file through the mkdir method.
Recommended: "PHP Video Tutorial"
If the php directory does not exist, create it:
The code is as follows:
function mkdirs($a1, $mode = 0777) { if (is_dir($a1) || @mkdir($al, $mode)) return TRUE; if (!mkdirs(dirname($a1), $mode)) return FALSE; return @mkdir($a1, $mode); } mkdirs("a1");
Description: The program determines whether the directory a1 exists. If it exists, it returns true. If it does not exist, it creates the directory a1. By default, it gives read, write and execute permissions. .
Note: 777 permissions are applicable to Linux environment.
The above is the detailed content of How to create a php directory if it does not exist. For more information, please follow other related articles on the PHP Chinese website!