Pyh.conf’25: a new PHP conference for the Russian-speaking community

Voting

: six minus two?
(Example: nine)

The Note You're Voting On

notepad at codewalkers dot com
20 years ago
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');

?>

<< Back to user notes page

To Top