PHP input Stream php://input use sample (PHP send picture stream to server) _php instance

Source: Internet
Author: User

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

Look at a simple example.

The client is a form, very simple.

Copy Code code as follows:

<form action= "" method= "POST" >
Name: <input type= "text" name= "name" value= "Tom"/><br/>
Age:<input type= "text" name= "Age" value= "/><br"
<input type= "Submit" value= "Submit"/>
</form>

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

Copy Code code as follows:

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

The official website about Php://input's note, repeatedly mentions $http_raw_post_data this variable, this variable actually and file_get_contents (php://input) content is the same. If you want to turn on this variable, you need to modify the configuration file, find the Always_populate_raw_post_data option, set to ON, and then restart the Web server. Using php://input does not require you to modify the PHP configuration file.

In the application of the project, such as camera photo, upload and save, you can use the php://input. After the client takes pictures, the picture is circulated to the server, the server uses file_get_getcontents (' Php://input ') to get the picture stream, and then the picture stream is saved to a file, this file is the picture.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.