What does PHP do with input and output?

Source: Internet
Author: User
Tags readfile stdin wrapper

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:

<formaction= "" method= "POST" >

<inputtype= "text" name= "test" ><inputtype= "Submit" Name= ""/>

</form>

<?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 output the entire contents of the http://www.phpcom.cn/in uppercase letters.

ReadFile ("php://filter/read=string.toupper/resource=http://www.phpcom.cn");

?>

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.