Reputation: 103597
I am newbie to php and so please do not mind me asking this question but am really getting confused as to why filemtime(filename.txt)
gives me as 31 Dec 1969 as my last modified time ?
Upvotes: 2
Views: 11635
Reputation: 21
I had the same problem and solved it by making the file path absolute by concatenating complete physical path before $filename
as file last modified date by filemtime($physical_path.$filename)
and file size by filesize($physical_path.$file)
.
Upvotes: 2
Reputation: 57794
You can't use
$t = filemtime(filename.txt);
At a minimum, use something like
$t = filemtime("filename.txt");
Upvotes: 0
Reputation: 449783
January 1, 1970 0:00 is the start of the Unix epoch. Thus, a timestamp of 0, which is the result of a failed filemtime operation, together with (probably) a DST issue, is December 31, 1969. You need to fix your filemtime operation, for example (if your example is not just pseudo-code) by adding quotes to the filename:
filemtime ("filename.txt");
Upvotes: 1
Reputation: 401182
This probably means your file was not found, either :
1st january 1970 is the date of time "zero" ; and filemtime
returns false
when there is a problem...
So, 31 Dec 1969 is the date/time of zero... According to your locale, I suppose ; I myself, with this code :
$filemtime = filemtime(filename.txt);
$formated = date('Y-m-d H:i:s', $filemtime);
var_dump($filemtime, $formated);
get this output :
boolean false
string '1970-01-01 01:00:00' (length=19)
false because the file doesnt' exist, and 1970-01-01
at 01:00
because of my locale (I'm in France, at UTC+1 hour)
And note I also get a couple of notices and warnings :
Notice: Use of undefined constant filename - assumed 'filename'
Notice: Use of undefined constant txt - assumed 'txt'
Warning: filemtime() [function.filemtime]: stat failed for filenametxt
Do you have any of those ?
If no : are error_reporting
and/or display_errors
enabled ?
Upvotes: 8