I need help with a function to create a 2 level directory for the following situations:
Thanks for the help.
// Desired folder structure $structure = './depth1/depth2/depth3/'; // To create the nested structure, the $recursive parameter // to mkdir() must be specified. if (! mkdir($structure, 0744, true)) { die('Failed to create folders...'); } Returns TRUE on success or FALSE on failure.
Methods: file_exists(): It is an inbuilt function that is used to check whether a file or directory exists or not. is_dir(): It is also used to check whether a file or directory exists or not. mkdir() : This function creates a directory.
The mkdir() creates a new directory with the specified pathname. The path and mode are sent as parameters to the mkdir() function and it returns TRUE on success or FALSE on failure. The mode parameter in mkdir() function is ignored on Windows platforms.
Use the third parameter of mkdir()
:
recursive Allows the creation of nested directories specified in the pathname. Defaults to FALSE.
$path = '/path/to/folder/with/subdirectory'; mkdir($path, 0777, true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With