I've get the file modification date for a local file with this code
<?php
$filename = 'db/ciupercomania.db';
if (file_exists($filename)) {
echo "This database was created on: <b>".date("F d Y H:i:s.", filemtime($filename)) . "</b><br/><br/>";
} else {
echo "File not exist.";
}
?>
but I'm struggling to get it for a dropbox hosted file, where I use this code:
<?php
$filename = 'https://www.dropbox.com/home/ciupercomania/Android_db?preview=Ciupercomania.db';
if (file_exists($filename)) {
echo "Out there is a database created on: <b>".date("F d Y H:i:s.", filemtime($filename)) . "</b><br/><br/>";
} else {
echo "File not exist.";
}
?>
I want to mention that I tried filectime as well as the dropbox link with extension ?dl=0 and ?dl=1 (automatic or by choice download) without success.
For the dropbox link I always get the FILE NOT EXIST message. If I don't echo it, I get a warning: Warning: filemtime(): stat failed for https://www.dropbox.com/home/ciupercomania/Android_db?preview=Ciupercomania.db
Edit
Based on ADyson observation and his provided links, combined with other searches on this theme. I found out that filemtime() only works with files on the same server, and I should look for other solutions like curl_getinfo() or get_header(). Based on that I'm tried these codes:
<?php
$url = 'https://www.dropbox.com/home/ciupercomania/Android_db?preview=Ciupercomania.db';
$curl = curl_init($url);
//don't fetch the actual page, i only want headers
curl_setopt($curl, CURLOPT_NOBODY, true);
//stop it from outputting stuff to stdout
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// attempt to retrieve the modification date
curl_setopt($curl, CURLOPT_FILETIME, true);
// disabling SSL verification to a HTTPS website, I don't care about it.
// curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
// curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
// disabling SSL verification for a HTTPS website, I don't care about it.
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
//Tell cURL where my certificate bundle is located.
// $certificate = "cert/cacert.pem";
// curl_setopt($curl, CURLOPT_CAINFO, $certificate);
// curl_setopt($curl, CURLOPT_CAPATH, $certificate);
//Check for errors.
if(curl_errno($curl)){
throw new Exception(curl_error($curl));
}
$result = curl_exec($curl);
// if ($result === false) {
// die (curl_error($curl));
// }
$timestamp = curl_getinfo($curl, CURLINFO_FILETIME);
if ($timestamp != -1) { //otherwise unknown
echo date("Y-m-d H:i:s", $timestamp);
}
?>
and this one
<?php
$url = 'https://www.dropbox.com/home/ciupercomania/Android_db?preview=Ciupercomania.db';
$h = get_headers($url, 1);
$dt = NULL;
if(!$h || strpos($h[0], '200') !== false){
$dt = new \DateTime($h['Last-Modified']);
echo $dt;
}
?>
First I've got SSL verification error and for that I tried both, ignoring it with CURLOPT_SSL_VERIFYHOST, false or CURLOPT_SSL_VERIFYHOST, 0, or by pointing at it with:
$certificate = "cert/cacert.pem";
curl_setopt($curl, CURLOPT_CAINFO, $certificate);
but without any success. I don't receive errors but neither a result.
Returning at ADyson's observation and since I'm really dumb, I would really appreciate it, if someone can point me to where I'm doing wrong and help me out.