API16

JFile/read

From Joomla! Documentation

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.

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'");returnfalse;}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 wantwhile(!feof($fh)&&(!$amount||strlen($data)<$amount)){$data.=fread($fh,$chunksize);}}fclose($fh);return$data;}