PHP for mobile phone photo upload avatar function

Source: Internet
Author: User

Now the mobile phone camera is very hot, so how to use the phone to take pictures and upload avatar? The reason is very simple, is the data transfer, the first mobile phone transmission of photo information, this is not post delivery is not a Get function pass,
This other data format is passed using $globals [' Http_raw_post_data '], which is similar to POST, but $globals [' Http_raw_post_data '] supports a richer data format, The detailed difference please oneself Baidu Google.
The design process is:
$GLOBALS [' Http_raw_post_data '] pass the photo data stream (binary)--open a blank image---> write the stream into a blank image--to determine if it is a valid picture---complete.
Note that the binary stream that passes the photo already contains the photo's size, format, and so on, and the time is to pass the phone picture information to the Web page.

Mobile phone side generally use flash cutting photo size, we all know that the picture and video is composed of binary stream, since the picture can be uploaded, then the video could not upload it? Does the principle have the same image as a mobile phone photo upload? You can study it yourself.

    /** Upload Picture class * @parameter; User ID * @date: 2011-8-15 * @author: CY **/      functionUpimg ($subdir){      //Set Storage Path    if(!Empty($subdir)){          $dirnow=GETCWD(); $folder=$dirnow." /cover/".$subdir;//folder where to save images          if( !Is_dir($folder) )mkdir($folder); //picture naming        $datenow=Date(' YMD '); $timenow= Time(); $image=$datenow.$timenow.‘. jpg; //whether the picture already exists        $check=$folder. ‘/‘ .$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 ']);//get the binary raw data from the post.                if(!Empty($png)){                      $file= @fopen($folder." /".$image, "W"); fwrite($file,$png);//Write                    fclose($file);//Close//orignal image Location                     $write _image=$folder. ‘/‘ .$image; }Else{                      $msg= "No Data Flow"; }                     if(Getimageinfo ($write _image)){                          $msg= "Upload succeeded"; }Else{$msg= "Picture format is incorrect";} }        }Else{          $msg= "Parameter Error"; }              return $msg; }            /** Check whether the picture is legal * @parameter; file name * @date: 2011-8-15 * @author: CY **/          functionGetimageinfo ($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 {                    //not a legitimate picture.                return false; }                        }    

When using XML-RPC, the server side obtains the client data, primarily via the PHP input stream input instead of the $_post array


According to the above several probes, we can make the following summary:
When the 1,content-type value is application/x-www-form-urlencoded, PHP will fill the HTTP request body with the corresponding data into the array $_post, fill in the $_ The data in the post array is the result of UrlDecode () parsing. (In fact, in addition to the Content-type, there are multipart/form-data that the data is the form data, we will introduce later)
2,php://input data, as long as Content-type is not multipart/form-data (the condition limit is described later). Then the php://input data is consistent with the HTTP entity body part data. The length of the data consistent with this section is specified by Content-length.
3, the $_post data is "consistent" with the Php://input data only if Content-type is application/x-www-form-urlencoded and the method of submission is the Post method (the quotation marks indicate that they are inconsistent in format. Consistent with the content). In other cases, they are inconsistent.
The 4,php://input cannot read $_get data. This is because the $_get data is written as Query_path in the Path field of the HTTP request header (header) instead of 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 because the XML_RPC data specification is XML, and its content-type is text/xml.

Reprint: http://www.cnblogs.com/y0umer/archive/2011/08/15/2809618.html

PHP for mobile phone photo upload avatar function

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.