Actions

API16

JStream/filesize

From Joomla! Documentation

< API16:JStream
Revision as of 17:47, 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

Retrieve the file size of the path

[Edit Descripton]

Description:JStream/filesize

Syntax

filesize()


Defined in

libraries/joomla/filesystem/stream.php

Importing

jimport( 'joomla.filesystem.stream' );

Source Body

function filesize()
{
        if(!$this->filename)
        {
                $this->setError(JText::_('File not open'));
                return false;
        }
 
        $retval = false;
        // Capture PHP errors
        $php_errormsg = '';
        $track_errors = ini_get('track_errors');
        ini_set('track_errors', true);
        $res = @filesize($this->filename);
        if(!$res)
        {
                $tmp_error = '';
 
                if($php_errormsg) { // some bad went wrong
                        $tmp_error = $php_errormsg; // store the error in case we need it
                }
 
                $res = JFilesystemHelper::remotefsize($this->filename);
 
                if(!$res)
                {
                        if($tmp_error) { // use the php_errormsg from before
                                $this->setError($tmp_error);
                        } else { // error but nothing from php? how strange! create our own
                                $this->setError(JText::_('Failed to get file size. This may not work for all streams!'));
                        }
                }
                else
                {
                        $this->_filesize = $res;
                        $retval = $res;
                }
        }
        else
        {
                $this->_filesize = $res;
                $retval = $res;
        }
        // restore error tracking to what it was before
        ini_set('track_errors',$track_errors);
        // return the result
        return $retval;
}

[Edit See Also] SeeAlso:JStream/filesize

Examples

<CodeExamplesForm />