note 104262 deleted from function.mkdir by danbrown
| From: | danbrown@php.net | Date: | Sat, 04 Jun 2011 17:27:41 +0000 |
| Subject: | note 104262 deleted from function.mkdir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180254@lists.php.net to get a copy of this message | ||
Note Submitter: evert at er dot nl
----
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);
}
}
}
}
}