filemtime(..) only works with files on your server.
$T=filesize("index.php"); // Works.
$T=filesize("/public_html/dir/index.php"); // Works.
But the following will not work.
$T=filesize("https://mydomain.com/dir/index.php"); // Will not work. Same domain but using web address.
$T=filesize("https://otherdomain.com/dir/index.php"); // Other domain, will not work.
To get file date for other sites try:
(Note: Time zone may be in G.M.T. and not your local timezone)
$T = getFileDate("https://mydomain.com/dir/index.php");
$T = getFileDate("https://otherdomain.com/dir/index.php");
function getFileDate($filePath){
// Same as filemtime(..) but also works with remote files.
// EG. = print date("j/m/Y, g:i:sa (e)",getFileDate("https://abc.com/file.jpg"));
// File not found then will return -307756800 ( 1/04/1960)
$ret = -(3562 *24*60*60); // 1/04/1960 3562= seconds to 1/01/1970
$ch = curl_init($filePath);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Try and get the file modification date.
curl_setopt($ch, CURLOPT_FILETIME, true);
$result = curl_exec($ch);
if($result===false){
die(curl_error($ch));
return $ret;
}
$ret = curl_getinfo($ch, CURLINFO_FILETIME);
curl_close($ch);
return $ret;
}