php Filemtime function showing wrong date

2020-07-18 09:36发布

I would like to add the last modified date to the index page , the below code shows the 31/12/1969 is the last modified date.

echo date("d/m/Y",filemtime("index.php"));

标签: php
2条回答
看我几分像从前
2楼-- · 2020-07-18 10:02

My guess is filemtime is not finding your file. filemtime will return 0, or something that equates to 0 like FALSE, and then applying date on time 0 will return 0 seconds since the epoch (1st Jan 1970).

Looks like that's what you're getting. I'm also guessing you're using PHP <= 5.1.

查看更多
手持菜刀,她持情操
3楼-- · 2020-07-18 10:08

I guess the path is wrong. At last on your development system you should increase the error settings.

In case of an erro filemtime() returns false, what what gets casted into 0 by the date()-call.

You should refer your files on the filesystem using (pseudo-)absolute paths.

__DIR__ . '/path/to/index.php';
查看更多
登录 后发表回答