PHP Fpassthru () function

Source: Internet
Author: User

Definition and usage

The Fpassthru () function outputs all the remaining data at the file pointer.

The function reads the given file pointer from the current location to EOF and writes the result to the output buffer.

Grammar
Fpassthru (file)
Parameters Description
File Necessary. Specifies the open file or resource to read.
Description

If an error occurs, Fpassthru () returns false. otherwise fpassthru () returns the number of characters read from file and passed to the output.

The file pointer must be valid and must point to a file that was successfully opened by fopen () or Fsockopen () (but not yet fclose () closed).

Hints and Notes

Tip: If you have already written data to a file, you must call Rewind () to point the file pointer to the file header.

Tip: If you are not modifying the file and not retrieving it at a specific location, just want to download the contents of the file to the output buffer, you should use ReadFile (), which eliminates the fopen () call.

Note: When using Fpassthru () for binary files in a Windows system, be sure to append B to the mode when you open the file with fopen () to open the file in binary mode. Encourage the use of the B flag when working with binaries, even if the system does not require it, to make the script more portable.

Example Example 1
<?php$file = fopen ("Test.txt", "R");//reads the first line fgets ($file);//sends the remainder of the file to the output cache echo fpassthru ($file); fclose ($file); >

Output:

There is three lines in the this file. The last line.59

Note: 59 indicates the number of characters passed.

Example 2

Dump the index page of the WWW server:

<?php$file = fopen ("http://www.example.com", "R"); Fpassthru ($file);? >

PHP Fpassthru () function

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.