Php readfile function

Source: Internet
Author: User
Tags readfile

Readfile
(PHP 4 and PHP 5)

Readfile-output a file

Description
International readfile (string $ file name [, Boolean $ use_include_path = false [, resource $ background])
Read the file and write it to the output buffer.

Parameters

File name
The file is read.

Use_include_path
You can use the optional second parameter to set it to TRUE. If you want to search the include_path file.

Background
Background stream resource.


Return value
The number of bytes returned to read the file. If an error occurs, it is false unless the returned function is @ readfile (). The error message is printed.

Instance

For example, #1 force download using readfile ()

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.