stat()函數(shù)可以返回有關(guān)文件的信息。
array stat ( string $filename )
該功能可以收集以filename命名的文件的統(tǒng)計(jì)信息。如果文件名是符號(hào)鏈接,則統(tǒng)計(jì)信息來(lái)自文件本身,而不是符號(hào)鏈接。lstat()函數(shù)與stat()函數(shù)相同,只不過(guò)它可以基于符號(hào)鏈接狀態(tài)。
<?php $stat = stat("/PhpProject/sample.txt"); //獲取文件狀態(tài) echo "Acces time: " .$stat["atime"]; //打印文件訪問(wèn)時(shí)間,與調(diào)用fileatime()相同 echo "\nModification time: " .$stat["mtime"]; //打印文件修改時(shí)間,與調(diào)用filemtime()相同 echo "\nDevice number: " .$stat["dev"]; // 打印設(shè)備號(hào) ?>
輸出結(jié)果
Acces time: 1590217956 Modification time: 1591617832 Device number: 1245376677
<?php $stat = stat("/PhpProject/sample.txt"); if(!$stat) { echo "stat() call failed..."; } else { $atime = $stat["atime"] + 604800; if(!touch("/PhpProject1/sampl2.txt", time(), $atime)) { echo "failed to touch file..."; } else { echo "touch() returned success..."; } ?>
輸出結(jié)果
touch() returned success...