php中實現視頻拍照

來源:互聯網
上載者:User
本篇文章主要介紹php中實現視頻拍照,感興趣的朋友參考下,希望對大家有所協助。

設計流程:$GLOBALS ['HTTP_RAW_POST_DATA']傳遞照片資料流(二進位)–>開啟一張空白圖—>把資料流寫進空白圖片裡面–判斷是否是有效圖片—完成。
注意傳遞照片的二進位流已經包含照片的尺寸大小,格式等等屬性,時間上就是把手機圖片資訊傳遞到web端頁面。
手機端一般使用flash切割照片大小,大家都知道圖片和視頻是由二進位流組成的,既然圖片可以上傳,那麼視頻能不能上傳呢?原理是不是和手機拍照上傳頭像一樣呢?自己可以去研究一下。
代碼如下

/* * 上傳圖片類 * @parameter; 使用者ID * @date:2015-10-08 * @author:cy * */function UpImg($subdir){// 設定儲存路徑if(!empty($subdir)){ $dirnow=getcwd(); $folder =$dirnow."/www.php100.com/".$subdir;// folder where to save images if( !is_dir($folder) ) mkdir($folder);// 圖片命名 $datenow=date('Ymd'); $timenow=time(); $image = $datenow.$timenow.'.jpg';// 圖片是否已存在 $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'] );//得到post過來的二進位未經處理資料 if(!empty($png)){ $file = @fopen($folder."/".$image, "w");   fwrite($file,$png);//寫入 hzhuti.com fclose($file);//關閉 // orignal image location  $write_image = $folder . '/' . $image; }else{ $msg = "沒有資料流"; } if(getimageInfo($write_image)){  $msg = "上傳成功"; }else{$msg = "圖片格式不正確";} }}else{ $msg = "參數錯誤";} return $msg; }/* * 檢測圖片是否合法 * @parameter; 檔案名稱 * @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 {   //不是 php100.com 合法的圖片   return false;  }  }

在使用xml-rpc的時候,server端擷取client資料,主要是通過php輸入資料流input,而不是$_POST數組
根據上面幾個探測,我們可以作出以下總結:
1、Content-Type取值為application/x-www-form-urlencoded時,php會將http請求body相應資料會 填入到數組$_POST,填入到$_POST數組中的資料是進行urldecode()解析的結果。(其實,除了該Content-Type,還有 multipart/form-data表示資料是表單資料,稍後我們介紹)
2、php://input資料,只要Content-Type不為multipart/form-data(該條件限制稍後會介紹)。那麼php: //input資料與http entity body部分資料是一致的。該部分相一致的資料的長度由Content-Length指定。
3、僅當Content-Type為application/x-www-form-urlencoded且提交方法是POST方法時,$_POST資料與php://input資料才是”一致”(打上引號,表示它們格式不一致,內容一致)的。其它情況,它們都不一致。
4、php://input讀取不到$_GET資料。是因為$_GET資料作為query_path寫在http要求標頭部(header)的PATH欄位,而不是寫在http請求的body部分。
這也協助我們理解了,為什麼xml_rpc服務端讀取資料都是通過file_get_contents(‘php://input', ‘r')。而不是從$_POST中讀取,正是因為xml_rpc資料規格是xml,它的Content-Type是text/xml。

總結:以上就是本篇文的全部內容,希望能對大家的學習有所協助。

相關推薦:

php 檔案上傳管理系統

php實現郵件發送的思路

使用PHP的APC模組製作上傳進度條

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.