PHP readfile() Function

❮ PHP Filesystem Reference

Example

Read a file:

<?php
echo readfile("test.txt");
?>
Run Example »

Definition and Usage

The readfile() function reads a file and writes it to the output buffer.

Tip: You can use a URL as a filename with this function if the fopen wrappers have been enabled in the php.ini file.

Syntax

readfile(file, include_path, context)

Parameter Values

Parameter Description
file Required. Specifies the file to read
include_path Optional. Set this parameter to TRUE if you want to search for the file in the include_path (in php.ini) as well
context Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream


Technical Details

Return Value: The number of bytes read on success, FALSE and an error on failure. You can hide the error message by adding an '@' in front of the function name
PHP Version: 4.0+
PHP Changelog: PHP 5.0: Added context support

❮ PHP Filesystem Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.