PHP input/output Stream Learning Note _php Tutorial

Source: Internet
Author: User

PHP input/output stream learning Notes


This article focuses on PHP input and output stream learning notes, PHP input and output streams are accessed through php://, which allows access to PHP input and output streams, standard input and output and error descriptors, in-memory, backup-to-disk temporary file streams, and filters that can manipulate other read-write file resources. A friend you need can refer to the following

PHP input and output streams are accessed through php://, which allows access to PHP's input and output streams, standard input and output and error descriptors, in-memory, backup-to-disk temporary file streams, and filters that can manipulate other read-write file resources.

Php://stdin, Php://stdout and Php://stderr

Php://stdin,php://stdout and Php://stderr allow access to the appropriate input or output streams of the PHP process.

Php://input

Php://input is a read-only stream of raw data that can access the request. Post request, it is best to use php://input instead of the $HTTP _raw_post_data (native POST data) because it does not rely on specific php.ini instructions and consumes less memory. The following example:

?

1

2

3

4

5

6

Echo file_get_contents ("Php://input");

?>

Results:

Php://output

Php://output is a write-only data stream that allows you to write to the output buffer in the same way as print and echo.

Php://fd

PHP://FD allows direct access to the specified file descriptor. For example, PHP://FD/3 references the file descriptor 3.

Php://memory and Php://temp

Php://memory and php://temp are data streams that are similar to file wrappers that allow temporary data to be read and written. The only difference between the two is that php://memory always stores the data in memory, and php://temp it into a temporary file after the amount of memory reaches a predefined limit (by default, 2MB). The temporary file location is determined in the same way as Sys_get_temp_dir ().

Php://filter

Php://filter is a meta-wrapper designed for filtering and filtering applications when data flow is turned on. This is useful for all-in-one (all-in-one) file functions, such as ReadFile (), file (), and file_get_contents (), without the opportunity to apply other filters before the data stream content is read. The parameters are as follows:

The following example:

?

1

2

3

4

/* This will output the entire contents of www.jb51.net in uppercase letters */

ReadFile ("Php://filter/read=string.toupper/resource=http://www.jb51.net");

?>

http://www.bkjia.com/PHPjc/1000113.html www.bkjia.com true http://www.bkjia.com/PHPjc/1000113.html techarticle PHP input/output Stream Learning notes This article mainly introduces the PHP input and output stream learning notes, PHP input and output stream is accessed through php://, it allows access to PHP input and output stream, superscript ...

  • 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.