JFile/read

Aus Joomla! Dokumentation
Wechseln zu: Navigation, Suche

JFile/read liest den Inhalt einer Datei.

Inhaltsverzeichnis

[Bearbeiten] Syntax

static read( $filename, [$incpath], [$amount], [$chunksize], [$offset] )
  • @return mixed - string Der Inhalt der Datei / bool false bei einem Fehler
  • @since Joomla 1.5
Parameter Datentyp Beschreibung Standardwert
$filename string Der komplette Pfad zur Datei ---
[$incpath] boolean Soll der Include Path genutzt werden ? false
[$amount] integer Die Menge die von der Datei gelesen werden soll 0
[$chunksize] integer Die Grösse der Stücke (chunks) 8192
[$offset] integer Der Versatz (offset) 0

[Bearbeiten] Beispiel

$fileName = 'pfad'.DS.'zur'.DS.'datei.txt';
 
if( ! $buffer = JFile::read($fileName) )
{
   echo 'Die Datei konnte nicht gelesen werden';
   return false;
}
 
echo $buffer;

[Bearbeiten] Siehe auch

[Bearbeiten] Quellcode

JFile::read in Joomla! 2.5.4

Folder blue.png libraries

  • Folder red.png joomla
    • Folder green.png filesystem
      • File php.png file.php
  1. public static function read($filename, $incpath = false, $amount = 0, $chunksize = 8192, $offset = 0)
  2. {
  3. // Initialise variables.
  4. $data = null;
  5. if ($amount && $chunksize > $amount)
  6. {
  7. $chunksize = $amount;
  8. }
  9.  
  10. if (false === $fh = fopen($filename, 'rb', $incpath))
  11. {
  12. JError::raiseWarning(21, JText::sprintf('JLIB_FILESYSTEM_ERROR_READ_UNABLE_TO_OPEN_FILE', $filename));
  13.  
  14. return false;
  15. }
  16.  
  17.  
  18. if ($offset)
  19. {
  20. fseek($fh, $offset);
  21. }
  22.  
  23. if ($fsize = @ filesize($filename))
  24. {
  25. if ($amount && $fsize > $amount)
  26. {
  27. $data = fread($fh, $amount);
  28. }
  29. else
  30. {
  31. $data = fread($fh, $fsize);
  32. }
  33. }
  34. else
  35. {
  36. $data = '';
  37. // While it's:
  38. // 1: Not the end of the file AND
  39. // 2a: No Max Amount set OR
  40. // 2b: The length of the data is less than the max amount we want
  41. while (!feof($fh) && (!$amount || strlen($data) < $amount))
  42. {
  43. $data .= fread($fh, $chunksize);
  44. }
  45. }
  46. fclose($fh);
  47.  
  48. return $data;
  49. }
Meine Werkzeuge
Namensräume
Varianten
Aktionen
Navigation
Sonstiges
Team Navigation
Werkzeuge