關於PHP 擷取視頻時間長度的代碼

來源:互聯網
上載者:User
本文通過執行個體代碼給大家介紹了php擷取視頻時間長度的相關知識,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧

具體代碼如下所示:

/** 獲得視頻檔案的縮圖和視頻長度* @date 2018-05-16* @copyright*///獲得視頻檔案的總長度時間和建立時間 根據視頻長度判斷是否失效public function getTime($url){  //擷取視頻重新導向後的連結  $location = locationUrl($url);  //擷取視頻Content-Length  $responseHead = get_data($location);  $list1 = explode("Content-Length: ", $responseHead);  $list2 = explode("Connection", $list1[1]);  $list = explode("x", $list2[0]);  return $list[0];}//擷取視頻重新導向後的連結function locationUrl($url){  $url_parts = @parse_url($url);  if (!$url_parts) return false;  if (!isset($url_parts['host'])) return false;  if (!isset($url_parts['path'])) $url_parts['path'] = '/';  $sock = fsockopen($url_parts['host'], (isset($url_parts['port']) ? (int)$url_parts['port'] : '80'), $errno, $errstr, 30);  if (!$sock) return false;  $request = "HEAD " . $url_parts['path'] . (isset($url_parts['query']) ? '?'.$url_parts['query'] : '') . " HTTP/1.1\r\n";  $request .= 'Host: ' . $url_parts['host'] . "\r\n";  $request .= "Connection: Close\r\n\r\n";  fwrite($sock, $request);  $response = '';  while(!feof($sock)) {    $response .= fread($sock, 8192);  }  fclose($sock);  if (preg_match('/^Location: (.+?)$/m', $response, $matches)){    if ( substr($matches[1], 0, 1) == "/" ){      return $url_parts['scheme'] . "://" . $url_parts['host'] . trim($matches[1]);    }    else{      return trim($matches[1]);    }  } else {    return false;  }}//審核視頻 curlfunction get_data($url){  $oCurl = curl_init();  //類比瀏覽器  $header[] = "deo.com";  $user_agent = "Mozilla/4.0 (Linux; Andro 6.0; Nexus 5 Build) AppleWeb/537.36 (KHTML, like Gecko)";  curl_setopt($oCurl, CURLOPT_URL, $url);  curl_setopt($oCurl, CURLOPT_HTTPHEADER,$header);  curl_setopt($oCurl, CURLOPT_HEADER, true);  curl_setopt($oCurl, CURLOPT_NOBODY, true);  curl_setopt($oCurl, CURLOPT_USERAGENT,$user_agent);  curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );  // 不用 POST 方式請求, 意思就是通過 GET 請求  curl_setopt($oCurl, CURLOPT_POST, false);  $sContent = curl_exec($oCurl);  // 獲得響應結果裡的:頭大小  $headerSize = curl_getinfo($oCurl, CURLINFO_HEADER_SIZE);  // 根據頭大小去擷取頭資訊內容  $header = substr($sContent, 0, $headerSize);  curl_close($oCurl);  return $header;}

以上就是本文的全部內容,希望對大家的學習有所協助,更多相關內容請關注topic.alibabacloud.com!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.