PHP input and output stream learning notes

Source: Internet
Author: User
Tags readfile stdin wrapper

This article mainly introduces the PHP input and output stream learning notes, PHP input and output streams are accessed through php://, which allows access to PHP's input and output streams, standard input and error descriptors, temporary file streams in memory, backup to disk, and filters that can manipulate other reads written to file resources. Need friends 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 error descriptors, temporary file streams in memory, backup to disk, and filters that can manipulate other reads written to file resources.

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

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

Php://input

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

?

1 2 3 4 5 6 <form action= "" method= "post" > <input type= "text" name= "Test" > <input type= "submit" Name= "/> </fo Rm> <?php 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 a file descriptor of 3.

Php://memory and Php://temp

Php://memory and php://temp are a data flow similar to the file wrapper that allows temporary data to be read and written. The only difference is that php://memory always stores the data in memory, and php://temp in the temporary file after the amount of memory reaches a predefined limit (the default is 2MB). The location of the temporary file 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 opened. This is useful for All-in-one (all-in-one) file functions, similar to ReadFile (), file (), and file_get_contents (), which have no opportunity to apply other filters before the data stream content is read. The parameters are as follows:

The following example:

?

< ? PHP/* This will be the capital letter output www.jb51.net All content * * * ReadFile ("php://filter/read=string.toupper/resource=http://www.jb51.net");? >

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.