具體代碼如下所示:
/** 獲得視頻文件的縮略圖和視頻長(zhǎng)度* @date 2018-05-16* @copyright//獲得視頻文件的總長(zhǎng)度時(shí)間和創(chuàng)建時(shí)間 根據(jù)視頻長(zhǎng)度判斷是否失效html' target='_blank'>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 方式請(qǐng)求, 意思就是通過(guò) GET 請(qǐng)求 curl_setopt($oCurl, CURLOPT_POST, false); $sContent = curl_exec($oCurl); // 獲得響應(yīng)結(jié)果里的:頭大小 $headerSize = curl_getinfo($oCurl, CURLINFO_HEADER_SIZE); // 根據(jù)頭大小去獲取頭信息內(nèi)容 $header = substr($sContent, 0, $headerSize); curl_close($oCurl); return $header;}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,更多相關(guān)內(nèi)容請(qǐng)關(guān)注PHP !
相關(guān)推薦:
PHP實(shí)現(xiàn)將HTML5中Canvas圖像保存到服務(wù)器
PHP 獲取某年第幾周的開(kāi)始日期和結(jié)束日期的實(shí)例講解
以上就是關(guān)于PHP 獲取視頻時(shí)長(zhǎng)的代碼的詳細(xì)內(nèi)容,PHP教程
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注