API16

JStream/chmod

< API16:JStream

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description

chmod wrapper



Syntax

chmod($filename='', $mode=0)
Parameter Name Default Value Description
$filename Mode to use
$mode 0

Defined in

libraries/joomla/filesystem/stream.php

Importing

jimport( 'joomla.filesystem.stream' );

Source Body

function chmod($filename='', $mode=0)
{
        if(!$filename)
        {
                if(!isset($this->filename) || !$this->filename) {
                        $this->setError(JText::_('Filename not set'));
                        return false;
                }
                $filename = $this->filename;
        }

        // if no mode is set use the default
        if(!$mode) $mode = $this->filemode;

        $retval = false;
        // Capture PHP errors
        $php_errormsg = '';
        $track_errors = ini_get('track_errors');
        ini_set('track_errors', true);
        $sch = parse_url($filename, PHP_URL_SCHEME);
        // scheme specific options; ftp's chmod support is fun
        switch($sch)
        {
                case 'ftp':
                case 'ftps':
                        $res = JFilesystemHelper::ftpChmod($filename, $mode);
                        break;
                default:
                        //echo '<p>Chmodding '. $filename . ' with ' . decoct($mode) .'</p>';
                        $res = chmod($filename, $mode);
                        break;
        }
        // seek, interestingly returns 0 on success or -1 on failure
        if(!$res) {
                $this->setError($php_errormsg);
        } else {
                $retval = true;
        }
        // restore error tracking to what it was before
        ini_set('track_errors',$track_errors);
        // return the result
        return $retval;
}



Examples

Code Examples


Advertisement