note 50839 added to function.filemtime
| From: | notepad at codewalkers dot com | Date: | Fri, 11 Mar 2005 09:53:23 +0000 |
| Subject: | note 50839 added to function.filemtime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86239@lists.php.net to get a copy of this message | ||
i needed the ability to grab the mod time of an image on a remote site. the following is the
solution with the help of Joe Ferris.
<?php
function filemtime_remote($uri)
{
$uri = parse_url($uri);
$handle = @fsockopen($uri['host'],80);
if(!$handle)
return 0;
fputs($handle,"GET $uri[path] HTTP/1.1\r\nHost: $uri[host]\r\n\r\n");
$result = 0;
while(!feof($handle))
{
$line = fgets($handle,1024);
if(!trim($line))
break;
$col = strpos($line,':');
if($col !== false)
{
$header = trim(substr($line,0,$col));
$value = trim(substr($line,$col+1));
if(strtolower($header) == 'last-modified')
{
$result = strtotime($value);
break;
}
}
}
fclose($handle);
return $result;
}
// echo filemtime_remote('http://www.somesite.com/someimage.jpg');
?>
----
Manual Page -- http://www.php.net/manual/en/function.filemtime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50839
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50839&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50839&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50839&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50839&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50839&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50839&report=yes
Search -- http://master.php.net/manage/user-notes.php