About PHP code to get video duration
This article introduces you to the relevant knowledge of php to obtain video duration through example code. It is very good and has certain reference value. Friends who need it can refer to it
The specific code is as follows:
/* * 获得视频文件的缩略图和视频长度 * @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; } } //审核视频 curl function 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; }
The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
PHP implements saving Canvas images in HTML5 to the server
PHP Gets the week of the year Examples of start date and end date
The above is the detailed content of About PHP code to get video duration. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
