PHP相关函数之file相关函数

2025-10-16 09:41:53

1、如何获取某文件的最后访问时间?

使用fileatime函数。

if (($fileatime = fileatime('./composer.json')) !== false) {

    echo date('Y-m-d H:i:s', $fileatime);

}

PHP相关函数之file相关函数

2、// 如何获取某文件inode节点的最后修改时间

if (($filectime = filectime('./composer.lock')) !== false) {

    echo date('Y-m-d H:i:s', $filectime);

}

PHP相关函数之file相关函数

3、// 如何获取某文件的组

print_r(posix_getgrgid(filegroup('./.env')));

PHP相关函数之file相关函数

4、// 如何获取某文件内容最后修改时间

if (($filemtime = filemtime('./composer.lock')) !== false) {

    echo date('Y-m-d H:i:s', $filemtime);

PHP相关函数之file相关函数

5、// 如何获取某文件的所属者owner

print_r(posix_getpwuid(fileowner('./.env.example')));

PHP相关函数之file相关函数

6、// 如何获取文件的权限

echo substr(sprintf('%o', fileperms('./.php_cs.cache')), -4);

PHP相关函数之file相关函数

7、最后我们执行一下这个php脚本,看下执行结果。执行结果如图。

PHP相关函数之file相关函数

8、完整脚本代码:

<?php                                                                                                                                                                                        

// 如何获取某文件的最后访问时间

if (($fileatime = fileatime('./composer.json')) !== false) {

    echo date('Y-m-d H:i:s', $fileatime);

}

echo PHP_EOL;

// 如何获取某文件inode节点的最后修改时间

if (($filectime = filectime('./composer.lock')) !== false) {

    echo date('Y-m-d H:i:s', $filectime);

}

echo PHP_EOL;

// 如何获取某文件的组

print_r(posix_getgrgid(filegroup('./.env')));

echo PHP_EOL;

// 如何获取某文件内容最后修改时间

if (($filemtime = filemtime('./composer.lock')) !== false) {

    echo date('Y-m-d H:i:s', $filemtime);

echo PHP_EOL;

// 如何获取某文件的所属者owner

print_r(posix_getpwuid(fileowner('./.env.example')));

echo PHP_EOL;

// 如何获取文件的权限

echo substr(sprintf('%o', fileperms('./.php_cs.cache')), -4);

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
相关推荐
  • 阅读量:100
  • 阅读量:142
  • 阅读量:22
  • 阅读量:192
  • 阅读量:147
  • 猜你喜欢