php readfile function_PHP tutorial

WBOY
Release: 2016-07-20 11:01:12
Original
1363 people have browsed it

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


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445475.htmlTechArticlephp readfile function readfile (PHP 4, PHP 5) readfile - Output a file description international readfile (String $filename[, boolean $use_include_path=false[, resources$background...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!