Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

readfile(3) [php man page]

READFILE(3)								 1							       READFILE(3)

readfile - Outputs a file

SYNOPSIS
int readfile (string $filename, [bool $use_include_path = false], [resource $context]) DESCRIPTION
Reads a file and writes it to the output buffer. PARAMETERS
o $filename - The filename being read. o $use_include_path - You can use the optional second parameter and set it to TRUE, if you want to search for the file in the include_path, too. o $context - A context stream resource. RETURN VALUES
Returns the number of bytes read from the file. If an error occurs, FALSE is returned and unless the function was called as @readfile(3), an error message is printed. EXAMPLES
Example #1 Forcing a download using readfile(3) <?php $file = 'monkey.gif'; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); readfile($file); exit; } ?> The above example will output something similar to:[NOT DISPLAYABLE MEDIA]Open / Save dialogue NOTES
Note readfile(3) will not present any memory issues, even when sending large files, on its own. If you encounter an out of memory error ensure that output buffering is off with ob_get_level(3). Tip A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen(3) for more details on how to specify the filename. See the "Supported Protocols and Wrappers" for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide. Note Context support was added with PHP 5.0.0. For a description of contexts, refer to "Streams". SEE ALSO
fpassthru(3), file(3), fopen(3), include(3), require(3), virtual(3), file_get_contents(3), "Supported Protocols and Wrappers". PHP Documentation Group READFILE(3)

Check Out this Related Man Page

STREAM_CONTEXT_GET_DEFAULT(3)						 1					     STREAM_CONTEXT_GET_DEFAULT(3)

stream_context_get_default - Retrieve the default stream context

SYNOPSIS
resource stream_context_get_default ([array $options]) DESCRIPTION
Returns the default stream context which is used whenever file operations (fopen(3), file_get_contents(3), etc...) are called without a context parameter. Options for the default context can optionally be specified with this function using the same syntax as stream_con- text_create(3). PARAMETERS
o $options -$options must be an associative array of associative arrays in the format $arr['wrapper']['option'] = $value. Note As of PHP 5.3.0, the stream_context_set_default(3) function can be used to set the default context. RETURN VALUES
A stream context resource. EXAMPLES
Example #1 Using stream_context_get_default(3) <?php $default_opts = array( 'http'=>array( 'method'=>"GET", 'header'=>"Accept-language: en " . "Cookie: foo=bar", 'proxy'=>"tcp://10.54.1.39:8000" ) ); $alternate_opts = array( 'http'=>array( 'method'=>"POST", 'header'=>"Content-type: application/x-www-form-urlencoded " . "Content-length: " . strlen("baz=bomb"), 'content'=>"baz=bomb" ) ); $default = stream_context_get_default($default_opts); $alternate = stream_context_create($alternate_opts); /* Sends a regular GET request to proxy server at 10.54.1.39 * For www.example.com using context options specified in $default_opts */ readfile('http://www.example.com'); /* Sends a POST request directly to www.example.com * Using context options specified in $alternate_opts */ readfile('http://www.example.com', false, $alternate); ?> SEE ALSO
stream_context_create(3), Listing of supported wrappers with context options ("Supported Protocols and Wrappers").. PHP Documentation Group STREAM_CONTEXT_GET_DEFAULT(3)
Man Page