This article mainly introduces the implementation of the video camera in PHP, interested in a friend's reference, I hope to be helpful to everyone.
design process:$GLOBALS [' Http_raw_post_data '] pass a photo stream (binary) –> open a blank image and write the data 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.
The code is as follows
/* * Upload picture class * @parameter; User ID * @date: 2015-10-08 * @author: CY * */function upimg ($subdir) {//Set storage path if (!empty ($subdir)) {$dirnow =getcwd (); $folder = $dirnow. " /www.php100.com/". $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 POST The binary raw data if (!empty ($png)) {$file = @fopen ($folder ." /". $image," w "); Fwrite ($file, $png);//write hzhuti.com fclose ($file);//close//orignal image location $write _image = $folder. '/' . $image; }else{$msg = "no Data Flow";} if (Getimageinfo ($write _image)) {$msg = "upload succeeded";} else{$msg = "image format is incorrect";}}} else{$msg = "parameter Error";} return $msg; }/* * Check whether the picture is legal * @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));//$i Magesize = FileSize ($imageInfo); return $info = Array (' width ' = = $imageInfo [0], ' height ' = = $imageInfo [1], ' type ' = = $imageType, ' mine ' = = $ Imageinfo [' Mine ']); } else {//not php100.com valid 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
Based on the above several probes, we can make the following summary:
1, Content-type value is application/x-www-form-urlencoded, PHP will be the HTTP request body corresponding data will be filled into the array $_post, fill in to $_ 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 the Content-type is not multipart/form-data (this condition limit will be introduced later). Then PHP: The//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, only when the Content-type is application/x-www-form-urlencoded and the method is the Post method, $_post data and php://input data is "consistent" (the quotation marks, indicating that their format is inconsistent, Consistent with the content). In other cases, they are inconsistent.
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.
:
Summary : The above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
PHP File Upload Management system
The idea of sending mail in PHP
Making an upload progress bar using PHP's APC module