Home > Backend Development > PHP Tutorial > PHP implementation of video taking and uploading avatar function example code_PHP tutorial

PHP implementation of video taking and uploading avatar function example code_PHP tutorial

WBOY
Release: 2016-07-20 11:12:19
Original
909 people have browsed it

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

/*
* Upload image class
* @parameter; User ID
* @date:2011-8-15
* @author:cy
* */
function UpImg($subdir){
//Set storage path
if(!empty($subdir)){
$dirnow=getcwd();
$folder =$dirnow."/www.bkjia.com/".$subdir;// folder where to save images
If( !is_dir($folder) ) mkdir($folder);

// Image naming
$datenow=date('Ymd');
$timenow=time();
$image = $datenow.$timenow.'.jpg';

// Whether the image 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 posted
if(!empty($png)){
$file = @fopen($folder."/".$image, "w");
             fwrite($file,$png);//Write hzhuti.com
​​fclose($file);//Close
// original image location
$write_image = $folder . '/' . $image;

}else{
$msg = "No data stream";
}
If(getimageInfo($write_image)){
        $msg = "Upload successful";
​ }else{$msg = "The 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
* */
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 {
//Not a legitimate picture from php100.com
              return false;
         } 

}

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.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444582.htmlTechArticleIf we want to implement video photography in php, we need to use the flash plug-in. We can then take the actual photos with flash. Accept data through $GLOBALS [HTTP_RAW_POST_DATA] in php, and then save it as a picture...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template