Re: remote files handling

From: Date: Wed, 14 Apr 2004 10:06:45 +0000
Subject: Re: remote files handling
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-183301@lists.php.net to get a copy of this message
Red Wingate wrote:
http://de.php.net/filemtime [quote] As of PHP 5.0.0 this function can also be used with some URL wrappers. Refer to Appendix J for a listing of which wrappers support stat() family of functionality. [/quote] -- red
As you likely don't have PHP5 installed, use fsockopen, filesystem functions to send and receive HEAD request, regexp to get Last-Modified header (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.29) and strtotime to get unix timestamp. Working example (I hope): <?php $fp = fsockopen("www.abc.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "HEAD /abc/Test.zip HTTP/1.1\r\n"; $out .= "Host: www.abc.com\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) {
       fgets($fp, 1024);
       if(ereg('^Last-Modified:\s+([^\r]+)', $m)) {
           echo strtotime($m[1]);
           break;
       }
} fclose($fp); } ?>

« previous php.general (#183301) next »