PHP 函数stat()
stat()函数可以返回有关文件的信息。
语法
array stat ( string $filename )
此函数可收集由文件名filename指定的文件的统计信息。如果filename是一个符号链接,统计信息将来自文件本身,而不是符号链接。lstat()函数与stat()函数相同,只是它可以根据符号链接的状态进行操作。
示例1
<?php
stat = stat("/PhpProject/sample.txt"); // Get file stat
echo "Acces time: " .stat["atime"]; // Print file access time, this is the same as calling fileatime()
echo "\nModification time: " .stat["mtime"]; //Print file modification time, this is the same as calling filemtime()
echo "\nDevice number: " .stat["dev"]; // Print the device number
?>
输出
Acces time: 1590217956
Modification time: 1591617832
Device number: 1245376677
示例2
<?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...";
}
?>
输出
touch() returned success...