当前位置:Gxlcms > PHP教程 > 简单介绍PHP获取文件属性方法_PHP教程

简单介绍PHP获取文件属性方法_PHP教程

时间:2021-07-01 10:21:17 帮助过:2人阅读

PHP获取文件属性之获取最近修改时间:

  1. < ?php
  2. $file = 'test.txt';
  3. echo date('r',
    filemtime($file));
  4. ?>

返回的说unix的时间戳,这在缓存技术常用.

相关PHP获取文件属性的还有获取上次被访问的时间fileatime(),filectime()当文件的权限,所有者,所有组或其它 inode 中的元数据被更新时间,fileowner()函数返回文件所有者

$owner = posix_getpwuid(fileowner($file));

(非window系统),ileperms()获取文件的权限,

  1. < ?php
  2. $file = 'dirlist.php';
  3. $perms = substr(sprintf
    ('%o', fileperms($file))
    , -4);
  4. echo $perms;
  5. ?>

filesize()返回文件大小的字节数:

  1. < ?php
  2. //
输出类似:somefile.txt:
1024 bytes
  • $filename = 'somefile.txt';
  • echo $filename . ': '
    . filesize($filename) . ' bytes';
  • ?>
  • PHP获取文件属性的全部信息有个返回数组的函数stat()函数:

    1. < ?php
    2. $file = 'dirlist.php';
    3. $perms = stat($file);
    4. var_dump($perms);
    5. ?>


    www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445971.htmlTechArticlePHP获取文件属性之获取最近修改时间: ?php $ file = 'test.txt' ; echodate('r', filemtime($file)); ? 返回的说unix的时间戳,这在缓存技术常用. 相关PHP获取...

    人气教程排行