0

I've come across a rather strange issue while building a file browser sort of app in PHP. For the purpose of this app, filemtime() is more useful to me, as I need the date of the last modification to the file's content. Unfortunately, the date returned by filemtime() see horribly wrong, being always lower than filectime(), most of the times by almost a year.

While I can conceive scenarios where this would be possible (if the file was chowned recently, but that was modified long ago). However, this is not the case, as all files were copied to the machine no more than a month and a half ago.

Code is this is simple

$mtime = date ("F d Y H:i:s.", filemtime(BASE_DIR.$target));
Brett Gregson
  • 5,867
  • 3
  • 42
  • 60
CatalinM
  • 520
  • 1
  • 5
  • 20
  • Can you show some examples? – Pekka Jan 20 '13 at 15:16
  • To see the difference between the two, I did the following `$diff = (filectime(BASE_DIR.$target) - filemtime(BASE_DIR.$target))/(60*60*24);` and got results between 0 and 440, depending on file. Results were always constant. – CatalinM Jan 20 '13 at 15:17

1 Answers1

1

AFAIK, this is normal. When copying files, the OS will sometimes set the creation time to the time of copying, while preserving the file's original "last modified" date.

I can't say which OSes and filesystem combinations support this, and I can't find any sources at a quick glance, but it's definitely something that I've seen happen on Windowses, OS Xes and *nixes.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • 1
    File were copied from OS X to a Linux machine. To be honest, I did think of this, as it seemed probable, but it did not seem to match my memories of those files. I will check again with info from the source machine to verify. – CatalinM Jan 20 '13 at 15:32
  • Well I'll be... you were right! The files did carry the mtime from the source. – CatalinM Jan 20 '13 at 16:32