Home >Backend Development >PHP Tutorial >A brief analysis of the use of php input stream php://input, input stream input_PHP tutorial

A brief analysis of the use of php input stream php://input, input stream input_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:19:39986browse

php input stream php://input usage brief analysis, input stream input

When making a function to take pictures with a camera and then upload them, php://input is used in php to obtain the content. So I learned about php://input.

From the official website information, php://input is a read-only information flow. When the request method is post and enctype is not equal to "multipart/form-data", you can use php://input to obtain it. The original requested data.

Look at a simple example.

The client is just a form, very simple.

Copy code The code is as follows:


name:

Age:




Submit the form to the server, and the server uses file_get_contents to obtain the php://input content
Copy code The code is as follows:

$content = file_get_contents("php://input");
echo $content; //Output name=tom&age=22

In the description of php://input on the official website, the variable $HTTP_RAW_POST_DATA is repeatedly mentioned. This variable is actually the same as the content of file_get_contents(php://input). If you want to enable this variable, you need to modify the configuration file, find the option always_populate_raw_post_data, set it to On, and then restart the web server. That's it. Using php://input does not require modifying the php configuration file.

In project applications, such as taking pictures with the camera, uploading and saving, you can use php://input. After the client takes a photo, it sends the image stream to the server. The server uses file_get_getcontents('php://input') to get the image stream, and then saves the image stream to a file. This file is the image.

Who knows, what is file_get_contents("php://input"); in php?

Reading the php input stream into a string is different from $_post and $_GET. Haha, for details, please see the manual

Save php://input

$content = file_get_contents("php://input");
file_put_contents('a.txt',$content);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/873341.htmlTechArticlephp input stream php://input usage brief analysis, input stream input is a function of making a camera to take pictures and then upload them , use php://input in php to obtain content. So I learned about php://input. ...
Statement:
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