Wednesday, February 20, 2008

readfile — Outputs a file

Description

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

Reads a file and writes it to the output buffer.

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 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(), an error message is printed.




session_cache_limiter
('none'); //*Use before session_start()
session_start();

$file = 'ASDFGgg.pdf';
_Download("files_dir/".$file, $file);

function
_Download($f_location,$f_name){
header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($f_location));
header('Content-Disposition: attachment; filename=' . basename($f_name));
readfile($f_location);
}

?>

0 comments: