php input stream php: and and input uses the example of php to send the image stream to the server

  • 2020-12-09 00:46:16
  • OfStack

According to the official website information, php://input is a read-only information flow. When the request is from post and enctype is not equal to "multipart/ form-ES7en", php://input can be used to obtain the data of the original request.

Let's look at a simple example.

The client is just a form, very simple.


<form action="" method="POST">
    name: <input type="text" name="name" value="tom" /><br />
    age:<input type="text" name="age" value="22" /><br />
    <input type="submit" value="Submit" />
</form>

The form is submitted to the server, which uses file_get_contents to get php://input content


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

In the explanation of php://input, the variable $HTTP_RAW_POST_DATA is repeatedly mentioned. This variable is actually the same as file_get_contents(php://input). To enable this variable, you need to modify the configuration file, find the always_populate_raw_post_data option, set it to On, and then restart the web server. Using php://input does not require modifications to the php configuration file.

php://input can be used in project applications, such as camera shooting, uploading and saving. After the client takes a picture, it sends the picture to the server. The server uses file_get_getcontents('php://input') to get the picture stream, and then saves the picture stream to a file, which is the picture.


Related articles: