Actions

API16

Difference between revisions of "JFile/read"

From Joomla! Documentation

< API16:JFile
(New page: ===Description=== Read the contents of a file <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> </span>...)
 
m (removing red link to edit, no existant pages)
 
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JFile/read|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JFile/read}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 83: Line 83:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JFile/read|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JFile/read}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
Line 98: Line 98:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API16]]

Latest revision as of 00:07, 13 May 2013

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

Read the contents of a file

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

read($filename, $incpath=false, $amount=0, $chunksize=8192, $offset=0)
Parameter Name Default Value Description
$filename $filename The full file path
$incpath false $incpath Use include path
$amount 0 $amount Amount of file to read
$chunksize 8192 $chunksize Size of chunks to read
$offset 0 $offset Offset of the file

Returns

mixed Returns file contents or boolean False if failed

Defined in

libraries/joomla/filesystem/file.php

Importing

jimport( 'joomla.filesystem.file' );

Source Body

function read($filename, $incpath = false, $amount = 0, $chunksize = 8192, $offset = 0)
{
        // Initialise variables.
        $data = null;
        if ($amount && $chunksize > $amount) { $chunksize = $amount; }
        if (false === $fh = fopen($filename, 'rb', $incpath)) {
                JError::raiseWarning(21, 'JFile::read: '.JText::_('Unable to open file') . ": '$filename'");
                return false;
        }
        clearstatcache();
        if ($offset) fseek($fh, $offset);
        if ($fsize = @ filesize($filename)) {
                if ($amount && $fsize > $amount) {
                        $data = fread($fh, $amount);
                } else {
                        $data = fread($fh, $fsize);
                }
        } else {
                $data = '';
                $x = 0;
                // While its:
                // 1: Not the end of the file AND
                // 2a: No Max Amount set OR
                // 2b: The length of the data is less than the max amount we want
                while (!feof($fh) && (!$amount || strlen($data) < $amount)) {
                        $data .= fread($fh, $chunksize);
                }
        }
        fclose($fh);
 
        return $data;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />