Special protocols in php, detailed explanation of php:// protocol

墨辰丷
Release: 2023-03-25 19:18:01
Original
2535 people have browsed it

This article mainly introduces the special protocols in php, php:// protocol is explained in detail, interested friends can learn more.

php://Access each input/output stream (I/O streams)


Description


PHP provides some miscellaneous input/output (IO) streams, allowing access to PHP's input and output streams, standard input and output, and error descriptors, in-memory, and disk backup Temporary file streams and filters that can operate on other read and write file resources.


php://stdin, php://stdout and php://stderr


##, and are allowed direct interview The corresponding input or output stream of the PHP process. The data stream references the copied file descriptor, so if you open and then close it, Just turning off the copy, the actually referenced

STDINis not affected. Note that PHP's behavior in this area was buggy until PHP 5.2.1. It is recommended that you simply use the constantsSTDIN,STDOUTandSTDERRinstead of manually opening these wrappers.

is read-only, and is write-only.


php://input


is a read-only stream that can access the requested raw data. In the case of POST requests, it is better to use instead of , as it does not rely on a specific directive. Moreover, in this case, there is no padding by default. Potentially requires less memory than activating always_populate_raw_post_data. enctype="multipart/form-data" is invalid.

Note:The opened data stream can only be read once; Data streams do not support seek operations. However, depending on the implementation of SAPI, when the request body data is saved, it can open another data stream and re-read it. Typically, this is only the case for POST requests, not other request methods such as PUT or PROPFIND.


##php://output


is a write-only data stream. Allows you to

print

the same way asechoWrite to the output buffer.


php://fd


Allows direct access to the specified file descriptor. For example, references file descriptor 3.


php://memory and php://temp


and is a similar file A wrapper for data streams that allows reading and writing temporary data. The only difference between the two is that always stores data in memory, while will be deleted after the amount of memory reaches a predefined limit (the default is 2MB) is stored in a temporary file. The determination of the temporary file location is consistent with

sys_get_temp_dir()

.

The memory limit can be controlled by adding /maxmemory:NN. NN is the maximum amount of data retained in memory in bytes. If it exceeds, temporary files will be used.


php://filter


is a meta wrapper, Designed for filtering applications when a data stream is opened. This is useful for all-in-one file functions likereadfile(),file()andfile_get_contents(), There is no opportunity to apply additional filters before the data stream content is read.

The target uses the following parameters as part of its path. Composite filter chains can be specified on a path. For detailed use of these parameters, please refer to specific examples.

php://filter Parameters
Name Description
resource= This parameter is required. It specifies the data stream you want to filter.
read= This parameter is optional. You can set one or more filter names, separated by pipe characters (|).
write= This parameter is optional. You can set one or more filter names, separated by pipe characters (|).
Any filter list not prefixed with read= or write= will be applied to read or write= as appropriate Write chain.


Optional



Update Log

##First of all, allow_url_include Only php://input, php://stdin, php://memory and php://temp. Allow reading Only php://stdin, php://input, php://fd, php://memory and php:// temp. Allow writing Only php://stdout, php://stderr, php://output, php://fd, php:// memory and php://temp. Allow appending Only php://stdout, php://stderr, php://output, php://fd, php://memory and php://temp (equal to writing) Allow simultaneous reading and writing Only php://fd, php://memory and php:// temp. Supports Only php://memory and php://temp. Support No Support No Supported No Supported No Only supports php://stdin , php://stdout, php://stderr, php://fd and php://temp.
Encapsulation protocol summary (forphp://filter, refer to the filtered wrapper. )
Attributes Supported
First followed by allow_url_fopen No
stat()
unlink()
rename()
mkdir()
rmdir()
stream_select()
Version Description
5.3.6 Added.
5.1.0 Added and .
5.0.0 Added.



##Example



##Example #1 php://temp/maxmemory


This optional option allows setting the maximum memory limit before starting to use temporary files.

Copy after login


##Example #2 php://filter/resource=

This parameter must be located at the end of and points to the data stream that needs to be filtered.

Copy after login

Example #3 php://filter/read=

This parameter takes one or multiple filter names separated by pipe characters |.

Copy after login


##Example #4 php://filter/write=


This parameter takes one or is separated by the pipe character | Multiple filter names.


Copy after login


##Related recommendations:
Http protocol post request parameters in PHP, php protocol post request_PHP tutorial

Http protocol post request parameters in PHP, php protocol post request

php post submission appears Input variables exceeded 1000

The above is the detailed content of Special protocols in php, detailed explanation of php:// protocol. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!