Actions

API15

JPath/setPermissions

From Joomla! Documentation

< API15:JPath
Revision as of 17:21, 22 March 2010 by Doxiki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Chmods files and directories recursivly to given permissions

[Edit Descripton]

Description:JPath/setPermissions

Syntax

setPermissions($path, $filemode= '0644', $foldermode= '0755')
Parameter Name Default Value Description
$path $path Root path to begin changing mode [without trailing slash]
$filemode '0644' $filemode Octal representation of the value to change file mode to [null = no change]
$foldermode '0755' $foldermode Octal representation of the value to change folder mode to [null = no change]

Returns

boolean True if successful [one fail means the whole operation failed]

Defined in

libraries/joomla/filesystem/path.php

Importing

jimport( 'joomla.filesystem.path' );

Source Body

function setPermissions($path, $filemode = '0644', $foldermode = '0755') {
 
        // Initialize return value
        $ret = true;
 
        if (is_dir($path))
        {
                $dh = opendir($path);
                while ($file = readdir($dh))
                {
                        if ($file != '.' && $file != '..') {
                                $fullpath = $path.'/'.$file;
                                if (is_dir($fullpath)) {
                                        if (!JPath::setPermissions($fullpath, $filemode, $foldermode)) {
                                                $ret = false;
                                        }
                                } else {
                                        if (isset ($filemode)) {
                                                if (!@ chmod($fullpath, octdec($filemode))) {
                                                        $ret = false;
                                                }
                                        }
                                } // if
                        } // if
                } // while
                closedir($dh);
                if (isset ($foldermode)) {
                        if (!@ chmod($path, octdec($foldermode))) {
                                $ret = false;
                        }
                }
        }
        else
        {
                if (isset ($filemode)) {
                        $ret = @ chmod($path, octdec($filemode));
                }
        } // if
        return $ret;
}

[Edit See Also] SeeAlso:JPath/setPermissions

Examples

<CodeExamplesForm />