簡體   English   中英

通過touch()更改文件的上次修改時間,並使用filemtime()獲取結果

[英]changing the file's last modified time through touch() and getting the result with filemtime()

所以我試圖獲取文件的最后修改日期,然后將其更新到當前時間,但是當我查看結果時,我在$ oldtime和$ newtime中獲得了SAME時間戳

$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));

touch文件后使用clearstatcache獲取正確的修改時間值。

因為您之前使用過filemtime ,所以緩存了結果,而在第二次調用時,結果從該緩存中提取而不是直接檢查文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM