Php video photo upload Avatar function for code sharing

Source: Internet
Author: User
How can I use my mobile phone to take a photo and upload an avatar? The reason is very simple, that is, data transmission. First, the mobile phone transmits the photo information, neither post transmission nor get function transmission. This is another type of data.

How can I use my mobile phone to take a photo and upload an avatar? The reason is very simple, that is, data transmission. First, the mobile phone transmits the photo information, neither post transmission nor get function transmission. This is another type of data.

If you want to implement video photography in php, you need to use the flash plug-in. After taking a photo from flash, we can use php's $ GLOBALS ['HTTP _ RAW_POST_DATA '] to accept the data, save it as an image. I will introduce it below.
$ GLOBALS ['HTTP _ RAW_POST_DATA '] is used. This system function is similar to post, but $ GLOBALS ['HTTP _ RAW_POST_DATA'] supports more data formats.
Design Process:
$ GLOBALS ['HTTP _ RAW_POST_DATA '] transmits 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 of the photo already contains the size, format, and other attributes of the photo. The time is to transfer the mobile phone image information to the web page.
The mobile phone uses flash to cut the Photo size. We all know that images and videos are composed of binary streams. Since images can be uploaded, can videos be uploaded? Is it the same principle as taking a photo on a mobile phone and uploading an avatar? You can study it yourself.
The Code is as follows:

/** Upload image class * @ parameter; User ID * @ date: 2015-10-08 * @ author: cy **/function UpImg ($ subdir) {// set the storage path if (! Empty ($ subdir) {$ dirnow = getcwd (); $ folder = $ dirnow. "/www.php100.com/". $ subdir; // folder where to save images if (! Is_dir ($ folder) mkdir ($ folder); // image name $ datenow = date ('ymmd'); $ timenow = time (); $ image = done '; // whether the image already exists $ check = $ folder.' http://www.jb51.net/ '. $ Image; if (file_exists ($ check) {unlink ($ check);} else {$ png = file_get_contents ('php: // input ')? File_get_contents ('php: // input'): gzuncompress ($ GLOBALS ['HTTP _ RAW_POST_DATA ']); // obtain the Binary Raw Data from post if (! Empty ($ png) {$ file = @ fopen ($ folder ." http://www.jb51.net/ ". $ Image, "w"); fwrite ($ file, $ png); // write hzhuti.com fclose ($ file ); // close // orignal image location $ write_image = $ folder.' http://www.jb51.net/ '. $ Image;} else {$ msg = "no data stream";} if (getimageInfo ($ write_image) {$ msg = "uploaded successfully ";} else {$ msg = "incorrect image format" ;}} else {$ msg = "parameter error";} return $ msg ;} /** check whether the image is valid * @ parameter; file name * @ date: 2011-8-15 * @ author: cy **/function getimageInfo ($ imageName = '') {$ imageInfo = getimagesize ($ imageName); if ($ imageInfo! = False) {$ imageType = strtolower (substr (image_type_to_extension ($ imageInfo [2]), 1); // $ imageSize = filesize ($ imageInfo ); return $ info = array ('width' => $ imageInfo [0], 'height' => $ imageInfo [1], 'type' => $ imageType, 'Mine '=> $ imageInfo ['Mine']);} else {// return false for an image that is not authorized by php100.com ;}}

When xml-rpc is used, the server obtains client data mainly through the php input stream input instead of the $ _ POST array.
Based on the above probes, We can summarize the following:
1. When the value of Content-Type is application/x-www-form-urlencoded, php will fill in the corresponding data of the http Request body to the array $ _ POST, the data filled in the $ _ POST array is the result of urldecode () parsing. (In fact, in addition to the Content-Type, there is also multipart/form-data indicating that the data is form data. We will introduce it later)
2. php: // input data, as long as the Content-Type is not multipart/form-data (this condition will be described later ). Php: // the input data is consistent with the part of the http entity body. The consistent data Length is specified by Content-Length.
3. Only when the Content-Type is application/x-www-form-urlencoded and the submission method is POST, $ _ POST data and php: // The input data is "consistent" (with quotation marks, indicating that the formats are inconsistent and the content is consistent. In other cases, they are inconsistent.
4. php: // input cannot read $ _ GET data. The reason is that the $ _ GET data is written in the PATH field of the http Request header as query_path, rather than in the http Request body.
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 because the xml_rpc data Type is xml, and its Content-Type is text/xml.

:

The above section describes how php implements the video photo upload Avatar function and hopes to help you learn it.

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.