- substr: documentation ( source)
- var_dump: documentation ( source)
- stream_get_meta_data: documentation ( source)
- strtotime: documentation ( source)
- strtolower: documentation ( source)
- fclose: documentation ( source)
- fopen: documentation ( source)
<?php
$url = 'http://cmps.cz/i/nar/YT-1954.jpg';
function GetRemoteLastModified( $uri )
{
// default
$unixtime = 0;
$fp = fopen( $uri, "r" );
if( !$fp ) {return;}
$MetaData = stream_get_meta_data( $fp );
foreach( $MetaData['wrapper_data'] as $response )
{
// case: redirection
if( substr( strtolower($response), 0, 10 ) == 'location: ' )
{
$newUri = substr( $response, 10 );
fclose( $fp );
return GetRemoteLastModified( $newUri );
}
// case: last-modified
elseif( substr( strtolower($response), 0, 15 ) == 'last-modified: ' )
{
$unixtime = strtotime( substr($response, 15) );
break;
}
}
fclose( $fp );
return $unixtime;
}
var_dump(GetRemoteLastModified('http://cmps.cz/i/nar/YT-1954.jpg'));