php readfile function
readfile
(PHP 4, PHP 5)
readfile - Output a file
Description
int readfile (string $filename[, boolean $use_include_path = false[, resource$background]])
Read the file and write to its output buffer.
Parameters
File name
The file is read.
use_include_path
You can use the optional second argument set to TRUE if you want to search the file in the include_path as well.
Background
Background stream resource.
Return value
Returns the number of bytes read from the file. If an error occurs, false unless returned by a function called @readfile(), an error message is printed.
Example
Example #1 force download using readfile()
$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('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
Ob_clean();
flush();
Readfile($file);
exit;
}
?>