php://
php://- access to individual input/output streams (I/O streams)
Description
PHP provides a number of miscellaneous input/output (IO) streams that allow access to PHP's input and output streams, standard input and output and error descriptors, in-memory, disk-backed 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 direct access to the appropriate input or output stream for the PHP process. The data stream refers to the copied file descriptor, so if you open php://stdin it and then close it, only the copy is turned off, and the actual reference is STDIN not affected. Note that PHP's behavior in this area has many bugs until PHP 5.2.1. It is recommended that you simply use constants STDIN , STDOUT and STDERR instead of manually opening these wrappers.
php://stdinis read-only, php://stdout and php://stderr is write-only.
Php://input
php://inputis a read-only stream of raw data that can access the request. In the case of a POST request, php://input It is best to use $HTTP_RAW_POST_DATA it instead, because it does not depend on specific php.ini instructions. And, in such cases, the $HTTP_RAW_POST_DATA default is no padding, which requires less memory than the active always_populate_raw_post_data. Enctype= "Multipart/form-data" php://input is invalid.
Note: php://input open streams can only be read once, and data streams do not support seek operations. However, depending on the implementation of the SAPI, when the request body data is saved, it can open another php://input data stream and reread it. Typically, this situation is only for POST requests, not other requests, such as PUT or PROPFIND.
Php://output
php://outputis 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://fdAllows direct access to the specified file descriptor. For example php://fd/3 , the file descriptor 3 is referenced.
Php://memory and Php://temp
php://memoryAnd php://temp is a data stream similar to a file wrapper that allows to read and write temporary data. The only difference between the two is that the php://memory data is always stored in memory, and the php://temp amount of memory reaches the predefined limit (by default, 2MB) into the temporary file. The temporary file location is determined in the same way as Sys_get_temp_dir ().
php://tempThe memory limit can be controlled by adding/maxmemory:nn, NN is the maximum amount of data in bytes, reserved in memory, and the temporary file is used.
Php://filter
php://filteris a meta-wrapper designed for filtering 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.
php://filterThe target uses the following parameters as part of its path. The composite filter chain can be specified on a path. Use these parameters in detail to refer to specific examples.
Php://filter parameters
| name |
Description |
| resource=< data stream to be filtered > |
This parameter is required. It specifies the data stream that you want to filter for filtering. |
| Filter List of read=< read chain > |
This parameter is optional. You can set one or more filter names separated by a pipe character (|). |
| write=< filter List of the Write chain > |
This parameter is optional. You can set one or more filter names separated by a pipe character (|). |
| <; filter List of two chains > |
Any filter list that does not have a prefix of read= or write= will be applied to read or write chains as appropriate. |
Options available
encapsulates the protocol summary (for Php://filter, refer to the filtered wrapper. )
| Properties |
Support |
| First in Allow_url_fopen |
No |
| First in Allow_url_include |
Only Php://input, Php://stdin, Php://memory, and Php://temp. |
| Allow read |
Only Php://stdin, Php://input, PHP://FD, Php://memory, and Php://temp. |
| Allow Write |
Only Php://stdout, Php://stderr, Php://output, PHP://FD, Php://memory, and Php://temp. |
| Allow Append |
Only Php://stdout, Php://stderr, Php://output, PHP://FD, Php://memory, and php://temp (equals write) |
| Allow simultaneous read and write |
Only PHP://FD, Php://memory and Php://temp. |
| Support stat () |
Only Php://memory and Php://temp. |
| Support unlink () |
No |
| Support rename () |
No |
| Support mkdir () |
No |
| Support rmdir () |
No |
| Only support Stream_select () |
Php://stdin, Php://stdout, Php://stderr, PHP://FD and Php://temp. |
Update log
| version |
Description |
| 5.3.6 |
Increased php://fd . |
| 5.1.0 |
Increased php://memory and php://temp . |
| 5.0.0 |
Increased php://filter . |
Example
Example #1 Php://temp/maxmemory
This optional option allows you to set php://temp the maximum memory limit before you start using temporary files.
<?php
// Set the limit to 5 MB.
$fiveMBs = 5 * 1024 * 1024;
$fp = fopen("php://temp/maxmemory:$fiveMBs", ‘r+‘);
fputs($fp, "hello\n");
// Read what we have written.
rewind($fp);
echo stream_get_contents($fp);
?>
Example #2 php://filter/resource=< data stream to be filtered >
This parameter must be at php://filter the end and point to the data stream that needs to be filtered.
<?php
/* 这简单等同于:
readfile("http://www.example.com");
实际上没有指定过滤器 */
readfile("php://filter/resource=http://www.example.com");
?>
Example #3 php://filter/read=< List of filters to be applied to the read chain >
This parameter takes one or a pipe character | Multiple filter names are separated.
<?php
/* 这会以大写字母输出 www.example.com 的全部内容 */
readfile("php://filter/read=string.toupper/resource=http://www.example.com");
/* 这会和以上所做的一样,但还会用 ROT13 加密。 */
readfile("php://filter/read=string.toupper|string.rot13/resource=http://www.example.com");
?>
Example #4 php://filter/write=< List of filters to be applied to the write chain >
This parameter takes one or a pipe character | Multiple filter names are separated.
<?php
/* 这会通过 rot13 过滤器筛选出字符 "Hello World"
然后写入当前目录下的 example.txt */
file_put_contents("php://filter/write=string.rot13/resource=example.txt","Hello World");
?>
Special protocol for PHP