public function setPermissions($permissions, $recursive = False)
{
if ($this->getExists() && is_numeric($permissions)) {
// '755' normalize to octal '0755'
$perms_oct = octdec(str_pad($permissions, 4, '0', STR_PAD_LEFT));
$success = @chmod($this->_realpath, $perms_oct);
if ($success) {
$this->_permissions = $permissions;
}
if ($success && $this->getIsDir() && $recursive) {
$contents = $this->getContents(True);
foreach ($contents as $filepath) {
if (!@chmod($filepath, $perms_oct)) {
$this->addLog('Unable to set permissions for "' . $filepath . '" to "' . $permissions . '"');
$success = False;
}
}
}
if ($success) {
return $this;
}
}
$this->addLog('Unable to change permissions for filesystem object to "' . $permissions . '"');
return False;
}