Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online

fread function syntax tag tutorial 2013





Alert! Connect with 10,000 Chating Online. Join Now

Php fread () function

Write your php code

 
<?php ?>

Php Result


Your code below



(PHP 3, PHP 4 , PHP 5)

fread -- Binary-safe file read

Syntax

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, EOF (end of file) is reached, or (for network streams) when a packet becomes available, 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);
?>

Warning

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);
?>

Warning

When reading from network streams or pipes, such as those returned when reading remote files or from popen() and fsockopen(), reading will stop after a packet is available. This means that you should collect the data together in chunks as shown in the example below.

<?php
$handle
= fopen("http://www.example.com/", "rb");
$contents = '';
while (!
feof($handle)) {
  
$contents .= fread($handle, 8192);
}
fclose($handle);
?>

Note: If you just want to get the contents of a file into a string, use file_get_contents() as it has much better performance than the code above.

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

Php fread Function syntax tag

fread php code on this is provided for your study purpose, it will guide you to know how create and design a website using php. use it to practice and train your self online



Php fread syntax tutorial

php tutorial guide and code design are for easy learning and programming. The code practice section provided at the top is for practising of this syntax. Use the code section up to practice your php programming online. Learning php is very easy, all you need is to use the examples on this site and practice them to perfect your skills.


Function index

Variables

Expressions

Operators

Control-Structures

Cookies

Array

Date & Time

Directory function

File

Image

Operators

Form data handling

Mathematics operators

Mail

Php Mysql

Network Functions

Strings

php tutorial guides,functions, classes, code examples and tags for creating simple dynamic site to mysql database driven sites
 
 
Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online