PHP.nl

stat

stat

Gives information about a file

 **stat** string $filename

Gathers the statistics of the file named by . If is a symbolic link, statistics are from the file itself, not the symlink. Prior to PHP 7.4.0, on Windows builds the , , and statistics have been from the symlink, in this case. filename``filename``size``atime``mtime``ctime

is identical to 

except it would instead be based off the symlinks status. lstat``stat

filenamePath to the file.

  • On Windows this will always be . 0

** Only valid on systems supporting the st_blksize type - other systems (e.g. Windows) return . -1

*** On Windows, as of PHP 7.4.0, this is the serial number of the volume that contains the file, which is a 64-bit integer, so may overflow. Previously, it was the numeric representation of the drive letter (e.g. for ) for , and for . unsigned2``C:``stat``0``lstat

**** On Windows, as of PHP 7.4.0, this is the identifier associated with the file, which is a 64-bit integer, so may overflow. Previously, it was always . unsigned0

***** On Windows, the writable permission bit is set according to the read-only file attribute, and the same value is reported for all users, group and owner. The ACL is not taken into account, contrary to . is_writable

The value of contains information read by several functions. When written in octal, starting from the right, the first three digits are returned by . The next digit is ignored by PHP. The next two digits indicate the file type:

So for example a regular file could be and a directory could be . mode``chmod``0100644``0040755

In case of error, returns false. stat

Upon failure, an is emitted. E_WARNING

Voorbeeld: example

<?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'];
?>

**Voorbeeld: Using information together with **

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

lstat``fstat``filemtime``filegroup``SplFileInfo