note 116550 deleted from function.ftp-mkdir by salathe
| From: | salathe@php.net | Date: | Fri, 06 Feb 2015 12:55:54 +0000 |
| Subject: | note 116550 deleted from function.ftp-mkdir by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-201602@lists.php.net to get a copy of this message | ||
Note Submitter: Payam Naderi
----
Make Directories Recuresively:
<?php
// It's part of my Filesystem Abstraction For FTP Driver
// @see https://github.com/phPoirot/Filesystem
// the function contains some method that not included here
// but it's self revealing.
// hope help someone
function mkDir(iDirectoryInfo $dir, iPermissions $mode)
{
$dirpath = $dir->filePath()->toString();
if (in_array($dirpath, ['.', '/']))
return $this;
$cwdTmp = $this->getCwd(); // store current working dir
// Its may included '.' or '' for leading slashes /dir
$pathSections = (explode('/', $dirpath));
do {
$mkdir = array_shift($pathSections);
} while(in_array($mkdir, ['.']));
if (!$this->isDir($mkdir)) {
// create directory if not exists
if (ftp_mkdir($this->getConnect(), $mkdir) === false)
throw new \Exception(sprintf(
'Failed To Make Directory "%s".'
, $mkdir
), null, new \Exception(error_get_last()['message']));
$this->chmod(new Directory($mkdir), $mode);
}
$this->chDir(new Directory($mkdir));
$this->mkDir(
new Directory(implode('/', $pathSections))
, $mode
);
$this->chDir($cwdTmp); // get back to working directory
return $this;
}
?>