Home >Backend Development >PHP Tutorial >PHP implementation of video taking and uploading avatar function example code_PHP tutorial
If we want to implement video photography in php, we need to use the flash plug-in. To take the actual photo with flash, we can accept the data through $GLOBALS ['HTTP_RAW_POST_DATA'] in php, and then save it as a picture. Let me introduce it below. .
Photography with mobile phones is very popular now, so how to use mobile phones to take photos and upload avatars? The reason is very simple, it is data transfer. First, the mobile phone transfers photo information. This is not a post transfer or a get function transfer,
This other data format is transferred using $GLOBALS ['HTTP_RAW_POST_DATA']. This system function is very similar to post, but $GLOBALS ['HTTP_RAW_POST_DATA'] supports richer data formats. For detailed differences, please search Baidu and Google .
The design process is:
$GLOBALS ['HTTP_RAW_POST_DATA'] transfers the photo data stream (binary) –> Open a blank image –> Write the data stream into the blank image – Determine whether it is a valid image – Complete.
Note that the binary stream used to transfer photos already contains the size, format, and other attributes of the photo. In terms of time, the mobile phone image information is transferred to the web page.
On mobile phones, flash is generally used to cut photo sizes. Everyone knows that pictures and videos are composed of binary streams. Since pictures can be uploaded, can videos be uploaded? Is the principle the same as taking photos with a mobile phone and uploading avatars? You can research it yourself
Just upload the code
The code is as follows | Copy code |
/* // Image naming // Whether the image already exists }else{ /* } |
When using xml-rpc, the server side obtains client data, mainly through the php input stream input, rather than the $_POST array
Based on the above detections, we can make the following summary:
1. When the Content-Type value is application/x-www-form-urlencoded, PHP will fill in the corresponding data of the http request body into the array $_POST, and the data filled in the $_POST array will be parsed by urldecode() result. (In fact, in addition to the Content-Type, there is also multipart/form-data indicating that the data is form data, which we will introduce later)
2. php://input data, as long as the Content-Type is not multipart/form-data (this condition will be introduced later). Then php: //input data is consistent with the http entity body part of the data. The length of this partially consistent data is specified by Content-Length.
3. Only when the Content-Type is application/x-www-form-urlencoded and the submission method is the POST method, the $_POST data and the php://input data are "consistent" (with quotation marks, indicating that their formats and contents are inconsistent) consistent). Otherwise, they are inconsistent.
4. php://input cannot read $_GET data. This is because the $_GET data is written in the PATH field of the http request header as query_path, rather than in the body part of the http request.
This also helps us understand why the xml_rpc server reads data through file_get_contents(‘php://input’, ‘r’). Instead of reading from $_POST, it is precisely because the data specification of xml_rpc is xml and its Content-Type is text/xml.