File stamp from remote server file.

I am trying to get the time stamp of a file on a remote server.
(Date/Time when the file was last uploaded or edited.)

[php]$timestamp = filemtime($url);[/php]
works if on same server (my server) and used to work on other servers with old PHP version.

[php]$timestamp = filemtime($url);[/php]
still works if on same server but not when reading file on some other server.

[php] $filePathName = “http://php.net/manual/en/function.curl-getinfo.php”;

$curl = curl_init($filePathName);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_exec($curl);
if(!curl_errno($curl)){
$timestamp = curl_getinfo($curl, CURLINFO_FILETIME);
// always cleanup.
curl_close($curl);
} else {
$timestamp = strtotime(“1066-01-01, 1:15:30”); // 1/01/1066 = Can’t read file date stamp.
}

print “File date = “.date(“j/m/Y, g:i:sa T”,$timestamp).”
\n”;
[/php]
Dose not work.
I can read the file contents with;

[php] $ch = curl_init($filePathName);
curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($curl);
curl_close($curl);
[/php]
Is there any other way to get filemtime() with PHP version 7.0.26 ?

Is there an ini_set(…,true) value to get filemtime(…) to work on a remote server.

I have access to the php files I have uploaded and can upload a .htaccess file.

I don’t think I have access with php.ini or httpd.conf as I can’t find them on my web space.

My website root is at;
/home/MyDirName/public_html
I do not have access to ‘/home’

The following works with some files but not all, as not all return a
Last-Modified: value in the header.

[php]/*
.txt works
.htm/.html works
.php dose not work (No Last-Modified: in header)
.jpg/.pnj works

*/

print date(j/m/Y",getTime(“http:domain.co/testfile.txt”))."
\n";

print date(j/m/Y",getTime(“http:domain.co/phpfile.php”))."
\n";

print date(j/m/Y",getTime(“http:domain.co/htmfile.htm”))."
\n";

function getTime($filePathName){
// Return the time stamp of file on remote server.

$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $filePathName,
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_NOBODY => true
));

$header = explode("\n", curl_exec($curl));
curl_close($curl);

$find = "Last-Modified: ";
for($loop=0; $loop<count($header); $loop=$loop+1){

// print $header[$loop]." ?<BR>";

if(strtolower(substr($header[$loop],0,strlen($find)))  == strtolower($find)){
  $timestamp = strtotime(substr($header[$loop],strlen($find)));
}

}

// print date(“j/m/Y - g:i:sa T”,$timestamp)."
\n";

return $timestamp;
}
[/php]

The issue is, there is no standard for this. So, you would need a class that can get the metadata, and extend the class for different types.

Sponsor our Newsletter | Privacy Policy | Terms of Service