How to use php input stream php://input

小云云
Release: 2023-03-20 21:52:02
Original
10246 people have browsed it

When making a function to take pictures with a camera and upload them, use php://input 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 get the original requested data.

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>
Copy after login


Submit the form to the server, and the server uses file_get_contents to obtain the content of php://input

$content = file_get_contents("php://input");
echo $content; //输出name=tom&age=22
Copy after login


In the official website’s description of php://input, repeatedly The variable $HTTP_RAW_POST_DATA is 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. 】

Related recommendations:

PHP input stream php://input example explanation

php input stream php://input usage Example (php sends image stream to server)

php input stream php input usage analysis

The above is the detailed content of How to use php input stream php://input. 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
Popular Tutorials
More>
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!