Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

readfile

Description

Outputs a file

Syntax

readfile ( string $filename [, bool $use_include_path = FALSE [, resource $context ]] ) : int

Parameters

filename

The filename being read.

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.

context

A context stream resource.

Return

Returns the number of bytes read from the file on success, or FALSE on failure

Examples

1

<?

$file = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/file.txt';

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;
}

?>
Hello
HomeMenu