File::read() – read bytes from a file


require_once 'File.php';

mixed File::read ( string $filename , int $size = FILE_DEFAULT_READSIZE , mixed $lock = false )


File::read() reads a specific amount of bytes from a specified file and returns them to the user.


  • string $filename - the file to read from

  • int $size - the number of bytes to read from the file (defaults to FILE_DEFAULT_READSIZE)

  • mixed $lock - lock type to use, FALSE if none

Return value

mixed - this function returns the requested bytes from the file if there were no errors, FALSE if it reached EOF or a PEAR_Error object if an error has occured during reading from file.


Possible PEAR_Error values
Error Code Error Value Meaning Solution
NULL "File does not exist: $filename" The file $filename does not exist. Check if the path that is passed to the function is correct.
NULL "Failed to open file: $filename" There are few possible things that might cause that error, usually it's caused by wrong permissions or bad sectors on the harddisk. Check the permissions of the file (ls -l {file} on UNIX systems) and change them so the file is readable by PHP, check if the harddisk is working properly and has no bad sectors.


This function can be called statically.


Using File::read()

require_once 'File.php';

//output 40 bytes of file
echo File::read("/path/to/"40);
checks wether the given path is an absolute path (Previous) reads a complete file (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.