首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

stat

(PHP 4, PHP 5, PHP 7)

stat - 提供有关文件的信息

描述

代码语言:javascript
复制
array stat ( string $filename )

收集以filename.命名的文件的统计信息。如果filename是符号链接,统计信息来自文件本身,而不是符号链接。

lstat()与stat()完全相同,除了它将基于符号链接状态。

参数

filename

文件的路径。

返回值

数字

联系

描述

0

dev

device number

1

ino

inode number *

2

mode

inode protection mode

3

nlink

number of links

4

uid

userid of owner *

5

gid

groupid of owner *

6

rdev

device type, if inode device

7

size

size in bytes

8

atime

time of last access (Unix timestamp)

9

mtime

time of last modification (Unix timestamp)

10

ctime

time of last inode change (Unix timestamp)

11

blksize

blocksize of filesystem IO **

12

blocks

number of 512-byte blocks allocated **

*在Windows上,这将始终为0。

**仅在支持st_blksize类型的系统上有效 - 其他系统(例如Windows)返回-1。

如果有错误,stat()返回FALSE

注意:由于PHP的整数类型是有符号的,并且许多平台使用32位整数,所以对于大于2GB的文件,某些文件系统函数可能会返回意外的结果。

错误/异常

发生故障时,E_WARNING被发出。

示例

Example #1 stat() example

代码语言:javascript
复制
<?php
/* Get file stat */
$stat = stat('C:\php\php.exe');

/*
 * Print file access time, this is the same 
 * as calling fileatime()
 */
echo 'Access time: ' . $stat['atime'];

/*
 * Print file modification time, this is the 
 * same as calling filemtime()
 */
echo 'Modification time: ' . $stat['mtime'];

/* Print the device number */
echo 'Device number: ' . $stat['dev'];
?>

Example #2 Using stat() information together with touch()

代码语言:javascript
复制
<?php
/* Get file stat */
$stat = stat('C:\php\php.exe');

/* Did we failed to get stat information? */
if (!$stat) {
    echo 'stat() call failed...';
} else {
    /*
     * We want the access time to be 1 week 
     * after the current access time.
     */
    $atime = $stat['atime'] + 604800;

    /* Touch the file */
    if (!touch('some_file.txt', time(), $atime)) {
        echo 'Failed to touch file...';
    } else {
        echo 'touch() returned success...';
    }
}
?>

注意

注意:请注意,时间分辨率可能因文件系统而异。

注意:这个函数的结果被缓存。有关更多详细信息,请参阅clearstatcache()。

提示

从PHP 5.0.0开始,这个函数也可以用于一些 URL包装器。请参阅支持的协议和包装以确定哪些包装支持stat()系列功能。

另请参阅

  • lstat() - 提供有关文件或符号链接的信息
  • fstat() - 使用打开的文件指针获取有关文件的信息
  • filemtime() - 获取文件修改时间
  • filegroup() - 获取文件组

← set_file_buffer

symlink →

扫码关注腾讯云开发者

领取腾讯云代金券