API16

JStream/filesize: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Retrieve the file size of the path <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</no...
 
m clean up
Line 2: Line 2:
Retrieve the file size of the path  
Retrieve the file size of the path  


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JStream/filesize|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JStream/filesize}}
 
{{subst:Description:JStream/filesize}}


===Syntax===
===Syntax===
Line 69: Line 67:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JStream/filesize|Edit See Also]]<nowiki>]</nowiki>
{{subst:SeeAlso:JStream/filesize}}
</span>
{{SeeAlso:JStream/filesize}}


===Examples===
===Examples===

Revision as of 14:26, 24 March 2017

Description

Retrieve the file size of the path


{{subst: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;
}


{{subst:SeeAlso:JStream/filesize}}

Examples

<CodeExamplesForm />