note 104262 added to function.mkdir
| From: | evert at er dot nl | Date: | Sat, 04 Jun 2011 11:50:33 +0000 |
| Subject: | note 104262 added to function.mkdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-180248@lists.php.net to get a copy of this message | ||
The recursive function is great, unless you want to be able to set user or group owner on every
directory part it creates. I run into problems creating a directory structure using the recursive
option running a CLI script, the www-data user/group was unable to use it (permission problems),
there for I created a simple create function:
public function create($path)
{
if (!is_dir($path)
{
$dirs = array();
//loop through path parts
foreach (explode("/", $path) as $dir)
{
$dirs[] = $dir;
//don't attempt anything when empty (always the first
/)
if ($dir)
{
//check if dir already exists
if (!is_dir(implode("/", $dirs)))
{
//do it all
mkdir (implode("/", $dirs));
chgrp (implode("/", $dirs), "www-data");
chmod (implode("/", $dirs), 0777);
}
}
}
}
}
----
Server IP: 213.249.64.162
Probable Submitter: 217.121.215.176
----
Manual Page -- http://www.php.net/manual/en/function.mkdir.php
Edit -- https://master.php.net/note/edit/104262
Del: integrated -- https://master.php.net/note/delete/104262/integrated
Del: useless -- https://master.php.net/note/delete/104262/useless
Del: bad code -- https://master.php.net/note/delete/104262/bad+code
Del: spam -- https://master.php.net/note/delete/104262/spam
Del: non-english -- https://master.php.net/note/delete/104262/non-english
Del: in docs -- https://master.php.net/note/delete/104262/in+docs
Del: other reasons-- https://master.php.net/note/delete/104262
Reject -- https://master.php.net/note/reject/104262
Search -- https://master.php.net/manage/user-notes.php