3

In php manual fileatime is defined as 'last access time of a file'.But in my code ,i opened and read the file content.But fileatime gives me a date back to february 16.Which means i last accessed the file in february 16 ??.But i accessed the file right now.Why it is not giving me the current date??

set_include_path('c://Users/shimantta/Desktop/');
$file='hehe.txt';
$open=fopen($file,'r');
echo fread($open,filesize($file)).'</br>';
echo "Last modified: ".date("F d Y H:i:s.",filemtime($file)).'</br>';
echo "Last modified: ".date("F d Y H:i:s.",fileatime($file)).'</br>';
echo "Last modified: ".date("F d Y H:i:s.",filemtime($file));

i am going to be copied here

Last modified: February 21 2015 19:57:21.

Last modified: February 16 2015 05:56:16.

Last modified: February 21 2015 19:57:21.

AL-zami
  • 8,902
  • 15
  • 71
  • 130

2 Answers2

4

filemtime() gives you the last time back where you changed the content.

And a quote from the manual:

This function returns the time when the data blocks of a file were being written to, that is, the time when the content of the file was changed.

EDIT:

Now I see it you're asking about fileatime(). fopen() doesn't update as you would expect the modification time. You want to use touch() to update the modification time.

Rizier123
  • 58,877
  • 16
  • 101
  • 156
4

The file access time should really be the last time, a file was accessed.

The thing is, that on many systems today, the access time is not maintained. For example, on mounting (e.g. fstab) it is possible to state, that the access time is not updated at all.

On many systems this feature is disabled, because SSDs will wear much faster of, when small changes will be made oftentimes, like changing the access time of files. I would guess, that the access time, you got, is the creation time, because on creation the time is written once and never updated.

So, you only have the modification time and the creation time (should also be available as separate time-stamp) available for one file.

Juergen
  • 12,378
  • 7
  • 39
  • 55