Creating new directories in PHP is accomplished using the mkdir() function, which takes two parameters. These parameters are, in order, a directory name you want to create and a permission mode for a new directory, which must be an octal number. The mode parameter is optional and has an effect only on Unix systems.
Have a look at the example:<?php
// if /path/to/my exists, this should return true
// if PHP has the right permissions
mkdir("/path/to/directory", 0777);
?>
By default, the mkdir() function only creates a directory if its parent exists. In PHP 5 the recursive parameter was added which should be true or false, depending on whether you want to create parent directories or not. In the following example, we pass true as a third parameter to mkdir(), so this makes the function act recursively to create any missing parent directories.
<?php
// will create /path/to/directory and
// also create /path and /path/to if needed and allowed
mkdir("/path/to/directory", 0777, true);
?>
0 comments:
Post a Comment