PHP相关函数之file相关函数

 时间:2026-02-14 12:11:38

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

  • PHP字符串相关函数
  • PHP常用函数大全
  • PHP可变函数总结
  • php之trim函数使用
  • php数组函数之list
  • 热门搜索
    杏鲍菇的做法大全家常 门图片大全 做梦掉牙怎么回事 初中周记200字大全 键盘符号快捷键大全 摩托车大全 怎么用ps去水印 肌肉痉挛怎么办 班旗设计图案大全 开心笑脸图片大全