stat

(PHP 4, PHP 5, PHP 7)

stat锟斤拷锟斤拷锟侥硷拷锟斤拷锟斤拷息

说锟斤拷

stat ( string $filename ) : array

锟斤拷取锟斤拷 filename 指锟斤拷锟斤拷锟侥硷拷锟斤拷统锟斤拷锟斤拷息锟斤拷锟斤拷锟� filename 锟角凤拷锟斤拷锟斤拷锟接o拷锟斤拷统锟斤拷锟斤拷息锟角癸拷锟节憋拷锟斤拷锟斤拷锟侥硷拷锟斤拷锟斤拷模锟斤拷锟斤拷锟斤拷欠锟斤拷锟斤拷锟斤拷印锟�

lstat() 锟斤拷 stat() 锟斤拷同锟斤拷只锟斤拷锟斤拷锟斤拷锟结返锟截凤拷锟斤拷锟斤拷锟接碉拷状态锟斤拷

锟斤拷锟斤拷

filename

锟侥硷拷锟斤拷路锟斤拷锟斤拷

锟斤拷锟斤拷值

stat() 锟斤拷 fstat() 锟斤拷锟截革拷式
锟斤拷锟斤拷锟铰憋拷 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 PHP 4.0.6锟斤拷 说锟斤拷
0 dev device number - 锟借备锟斤拷
1 ino inode number - inode 锟斤拷锟斤拷
2 mode inode protection mode - inode 锟斤拷锟斤拷模式
3 nlink number of links - 锟斤拷锟斤拷锟斤拷锟斤拷目
4 uid userid of owner - 锟斤拷锟斤拷锟竭碉拷锟矫伙拷 id
5 gid groupid of owner- 锟斤拷锟斤拷锟竭碉拷锟斤拷 id
6 rdev device type, if inode device * - 锟借备锟斤拷锟酵o拷锟斤拷锟斤拷锟� inode 锟借备锟侥伙拷
7 size size in bytes - 锟侥硷拷锟斤拷小锟斤拷锟街斤拷锟斤拷
8 atime time of last access (unix timestamp) - 锟较次凤拷锟斤拷时锟戒(Unix 时锟斤拷锟斤拷锟�
9 mtime time of last modification (unix timestamp) - 锟较达拷锟睫革拷时锟戒(Unix 时锟斤拷锟斤拷锟�
10 ctime time of last change (unix timestamp) - 锟较次改憋拷时锟戒(Unix 时锟斤拷锟斤拷锟�
11 blksize blocksize of filesystem IO * - 锟侥硷拷系统 IO 锟侥匡拷锟叫�
12 blocks number of blocks allocated - 锟斤拷占锟捷匡拷锟斤拷锟侥�
* Windows 锟斤拷锟斤拷锟斤拷 0锟斤拷

* - 锟斤拷锟斤拷支锟斤拷 st_blksize 锟斤拷锟酵碉拷系统锟斤拷锟斤拷效锟斤拷锟斤拷锟斤拷系统锟斤拷锟斤拷 Windows锟斤拷锟斤拷锟斤拷 -1锟斤拷

锟斤拷锟斤拷锟斤拷锟�stat() 锟斤拷锟斤拷 FALSE锟斤拷

Note: 锟斤拷为 PHP 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟叫凤拷锟斤拷锟斤拷锟酵讹拷锟揭很讹拷平台使锟斤拷 32 位锟斤拷锟酵o拷锟斤拷 2GB 锟斤拷锟较碉拷锟侥硷拷锟斤拷一些锟侥硷拷系统锟斤拷锟斤拷锟斤拷锟杰凤拷锟斤拷锟睫凤拷预锟节的斤拷锟� 锟斤拷

锟斤拷锟斤拷锟届常

锟斤拷锟斤拷时锟斤拷锟斤拷锟� E_WARNING 锟斤拷锟斤拷拇锟斤拷锟�

锟斤拷锟斤拷锟斤拷志

锟芥本 说锟斤拷
4.0.6 锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷募锟斤拷锟酵筹拷锟斤拷锟较拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟叫筹拷锟侥碉拷元锟斤拷锟斤拷锟斤拷锟铰憋拷锟斤拷憧硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街拷锟斤拷曰锟斤拷锟斤拷锟酵拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷省锟�

锟斤拷锟斤拷

Example #1 stat() 锟斤拷锟斤拷

<?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()

<?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...';
    }
}
?>

注锟斤拷

Note:

注锟解:锟斤拷同锟侥硷拷系统锟斤拷时锟斤拷锟斤拷卸戏锟斤拷锟斤拷锟斤拷锟斤拷遣锟斤拷锟酵拷摹锟�

Note: 锟剿猴拷锟斤拷锟侥斤拷锟斤拷岜伙拷锟斤拷妗o拷渭锟� clearstatcache() 锟皆伙拷酶锟斤拷锟较革拷凇锟�

Tip

锟斤拷 PHP 5.0.0 锟斤拷, 锟剿猴拷锟斤拷也锟斤拷锟斤拷某些 URL 锟斤拷装锟斤拷锟斤拷锟斤拷渭锟� 支锟街碉拷协锟斤拷头锟阶靶拷锟�锟皆伙拷锟街э拷锟� stat() 系锟叫猴拷锟斤拷锟斤拷锟杰的帮拷装锟斤拷锟叫憋拷

锟轿硷拷

  • lstat() - 锟斤拷锟斤拷一锟斤拷锟侥硷拷锟斤拷锟斤拷锟斤拷锟斤拷拥锟斤拷锟较�
  • fstat() - 通锟斤拷锟窖打开碉拷锟侥硷拷指锟斤拷取锟斤拷锟侥硷拷锟斤拷息
  • filemtime() - 取锟斤拷锟侥硷拷锟睫革拷时锟斤拷
  • filegroup() - 取锟斤拷锟侥硷拷锟斤拷锟斤拷