PHP Directories
Making New Directories
Problem
You want to create a directory.
Solution
Use mkdir():
mkdir('/tmp/apples',0777) or die($php_errormsg);
Discussion
The second argument to mkdir() is the permission mode for the new directory, which must be an octal number. The current umask is taken away from this permission value to create the permissions for the new directory. So, if the current umask is 0002, callingkdir(/tmp/apples,0777) sets the permissions on the resulting directory to 0775 (user and group can read, write, and execute; others can only read and execute).
By default, mkdir() only creates a directory if its parent exists. For example, if /usr/local/images doesn’t exist, you can’t create /usr/local/images/puppies. To create a directory and its parents, pass true as a third argument to mkdir(). This makes the function act recursively to create any missing parent directories.
No comments:
Post a Comment