为什么我在1969年12月31日作为我最后修改的文件名在php中使用filemtime? [英] Why do I get 31 Dec 1969 as my last modified filename using filemtime in php?

查看:160
本文介绍了为什么我在1969年12月31日作为我最后修改的文件名在php中使用filemtime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PHP的新手,所以请不要介意我问这个问题,但我真的很困惑,为什么 filemtime(filename.txt)给了我12月31日1969作为我最后修改的时间?

解决方案

这可能意味着您的文件未找到,




  • ,因为它不存在

  • 或者因为它不在currect目录中

  • 或者因为你没有引用它的名字 - 你没有^^



1970年1月1日是日期零;和 filemtime 返回 false 出现问题时...



因此,1969年12月31日是零的日期/时间......根据你的语言环境,我想;我自己,用这段代码:

  $ filemtime = filemtime(filename.txt); 
$ formated = date('Y-m-d H:i:s',$ filemtime);
var_dump($ filemtime,$ formated);

获得此输出:

  boolean false 
string'1970-01-01 01:00:00'(length = 19)

错误,因为文件不存在,并且 1970-01-01 at 01:00 因为我的语言环境(我在法国,在UTC + 1小时)





注意我还收到了一些通知和警告:


  • 注意:使用未定义的常量文件名 - 文件名'

  • 注意:使用未定义的常量txt - 假设'txt'

  • 警告:filemtime()[function.filemtime]:stat文件名失败



你有这些吗?

如果不是: error_reporting
和/或 display_errors 启用了吗?


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 ?

解决方案

This probably means your file was not found, either :

  • because it doesn't exist
  • or because it's not in the currect directory
  • or because you didn't quote its name -- you didn't ^^

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 ?

这篇关于为什么我在1969年12月31日作为我最后修改的文件名在php中使用filemtime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆