PHP fread() function

This function is used to read an open file.

Syntax

fread(filename, filesize );

Both filename & filesize are the required parameters. This function reads the file up to the specified filesize from the file pointer of given file name. This function returns the read string and FALSE on failure condition.

Example1

<?php
    $getfile = fopen('demo.txt', "r");
    fread($getfile, filesize($getfile));
?>

The above code reads the entire file.

Example2

<?php
    $getfile = fopen('demo.txt', "r");
    fread($getfile, 100);
?>

The above code reads the 100 bytes from the file.





Related PHP Functions

PHP array_reverse() function
PHP array_diff() function
PHP array_key_exists() function
PHP array_push() function
PHP array_search() function
PHP class_exists() function
PHP curl_setopt() function
PHP die() function
PHP dirname() function
PHP each() function
PHP explode() function
PHP file_exists() function
PHP function_exists() function
PHP getenv() function
PHP is_readable() function
PHP ksort() function
PHP mkdir() function
PHP ob_start() function
PHP parse_url() function
PHP str_repeat() function
PHP substr() function




Read more articles


General Knowledge



Learn Popular Language