Search code examples
phpsizeflv

How to know size of flv size from url?


If I know flv video, for example:

www.domain.com/video.flv

I can't use "filesize" because it doesn't able to check size from external url, right?
So, how can I know his size?


Solution

  • You can use CURL to get the headers of a remote file, including the size of a file.

    $url = 'http://www.domain.com/video.flv';
    
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_HEADER, true); 
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    $headers = curl_exec($ch);
    
    $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
    
    curl_close($ch); 
    

    Setting CURLOPT_NOBODY to true, makes CURL not download the body of a requested URL.