php中文件的属性及方法

文件都有相应的属性,文件大小、文件类型、修改时间、创建时间、读写权限等。

php提供获取这些属性的函数。

  • file_exists() 检查指定的文件和目录是否存在。

  • filesize() 获取文件的大小,单位是B(字节)。

  • is_readable() 检查文件是否可读。

  • is_writable() 检查文件是否可写。

  • is_executable() 检查文件是否可执行

  • filectime() 获取文件的创建时间,返回Unix时间戳。

  • filemtime() 获取文件的最后修改时间,返回Unix时间戳。

  • fileatime() 获取文件的最后访问时间,返回Unix时间戳。

  • stat() 获取文件的大部分属性,返回一个数组。

如下代码:

<?php 
        
    /**
     * @author youthflies
     * 获取文件的属性
     */
    $fileName = "/home/youthflies/downloads/jdk-6u37-linux-i586.bin";
        
    if(!file_exists($fileName))
    {
        echo "File do not exists!";
        return;
    }
        
    echo "File size : " . filesize($fileName) . "<br />";
    echo "File read : " . is_readable($fileName) . "<br />";
    echo "File write : " . is_writable($fileName) . "<br />";
    echo "File execute : " . is_executable($fileName) . "<br />";
    echo "File created time : " . date("Y-m-d h:i:s", filectime($fileName)) . "<br />";
    echo "File modified time : " . date("Y-m-d h:i:s", filemtime($fileName)) . "<br />";
    echo "File acess time : " . date("Y-m-d h:i:s", fileatime($fileName)) . "<br />";
    echo "File properties : ";
    print_r(stat($fileName));
        
    
?>

上面文件运行结果:

File size : 71764073
File read : 1
File write : 1
File execute : 1
File created time : 2012-11-28 02:20:19
File modified time : 2012-11-27 02:13:01
File acess time : 2012-11-27 02:15:22
File properties : Array(    [0] => 2055    [1] => 2228791    [2] => 33279    [3] => 1    [4] => 1000    [5] => 1000    [6] => 0    [7] => 71764073    [8] => 1353996922    [9] => 1353996781    [10] => 1354083619    [11] => 4096    [12] => 140168    [dev] => 2055    [ino] => 2228791    [mode] => 33279    [nlink] => 1    [uid] => 1000    [gid] => 1000    [rdev] => 0    [size] => 71764073    [atime] => 1353996922    [mtime] => 1353996781    [ctime] => 1354083619    [blksize] => 4096    [blocks] => 140168)

转载于:https://my.oschina.net/u/147181/blog/164854

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值