Search code examples
phpdatehyperlinkfilemtime

How use filemtime with a link?


I would like to know, how to use "filemtime" with a link?

Example:

Thanks in advance for your help!


Solution

  • The built-in http wrapper doesn't support stat family of functionality, like filemtime. So: you can't.

    HTTP protocol define a Last-Modified header field that you may use instead. With CURL:

    $curl = curl_init('http://thegoodwebsite.net/i/banp.gif');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_NOBODY, true);
    curl_setopt($curl, CURLOPT_FILETIME, true);
    
    if (false !== curl_exec($curl)) {
        $time = curl_getinfo($curl, CURLINFO_FILETIME);
        echo 'remote time of the retrieved document: ', $time;
    }
    
    curl_close($curl); 
    

    If you get -1 it might be unknown.