Changing the last modified file time using touch () and getting the result using filemtime ()

So, I'm trying to get the date the file was last modified, and then update it to the current time, but when I look at the result, I get a SAME timestamp in both $ oldtime and $ newtime

$file = 'test.txt'; $oldtime = filemtime($file); touch($file, time()); $newtime = filemtime($file); echo '<h1>old</h1>'; print_r(getdate($oldtime)); echo '<h1>new</h1>'; print_r(getdate($newtime)); 
+6
source share
1 answer

Use clearstatcache after the touch ing file to get the correct modification time value.

Since you used filemtime before, the result for it was cached, and on the second call, the result is pulled from this cache instead of checking the file directly.

+13
source

Source: https://habr.com/ru/post/948380/


All Articles