Reading a file : fread « File Directory « PHP






Reading a file

 
<html>

 <head>
  <title>Reading a file</title>
 </head>

 <body>
 
 <?php 
  $filename = "data.txt";
  $filesize = filesize($filename);
  $file = fopen( $filename, "r" );
  $text = fread( $file, $filesize );
  fclose( $file ); 

  echo( "File Size: $filesize bytes" ); 
  echo( "<pre>$text</pre>" );
 ?>

 </body>

</html>
  
  








Related examples in the same category

1.fread( ) is good for when you only care about a small part of the file.
2.fread() function reads up to length bytes from the file, returning the file's contents.
3.fread.php
4.fopen( ) and fread( )
5.Reading and Writing Binary Data in a File