UltraWebsiteHosting.comUltraWebsiteHosting.com
 

fread

(PHP 3, PHP 4 )

fread -- Binary-safe file read

Description

string fread ( resource handle, int length)

fread() reads up to length bytes from the file pointer referenced by handle. Reading stops when length bytes have been read or EOF (end of file) reached, whichever comes first.

<?php
// get contents of a file into a string
$filename = "/usr/local/something.txt";
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
?>

Note: On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen() mode parameter.

<?php
$filename = "c:\\files\\somepic.gif";
$handle = fopen ($filename, "rb");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
?>

See also fwrite(), fopen(), fsockopen(), popen(), fgets(), fgetss(), fscanf(), file(), and fpassthru().



Go back to index



Have unlimited websites hosted for as low as $5.95 a month! Check out our new Hosting Plans!


Note: Documentation is made available for our clients. The application's homepage is located at PHP.net


 


All pages Copyright © 2002-2008 by Flux Services, Inc. All rights reserved.
All trademarks used are properties of their respective owners.
Refund Policy  Privacy Statement  Service Agreement


< >