1. Computing

Read & Return Data From Files Into PHP

By , About.com Guide

2 of 5

Using fread () in PHP
You can use fread () when you want to read the file data and return it to a string. You can specify how many bytes to read, but 8192 is the maximum. If you choose to use this method, you must be sure to open the file first.
 <?php 
 $YourFile = "YourFile.txt"; 
 $handle = fopen($YourFile, 'r'); 
 $Data = fread($handle, 512); 
 fclose($handle); 
 print $Data; 
 ?> 
This code opens the file YourFile.txt from your server and puts it's entire contents into the variable $Data as a string. We then print $Data, so the script is basically outputting the file contents onto a page.
  1. About.com
  2. Computing
  3. PHP / MySQL
  4. Advanced PHP
  5. fread - fread php - fread tutorial

©2013 About.com. All rights reserved.