Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

stat()

Example

Retrieve details about a file.

<?php
$stat = stat(“test.txt”);
echo “Access time: “ .$stat[“atime”];
echo “<br>Modification time: “ .$stat[“mtime”];
echo “<br>Device number: “ .$stat[“dev”];
?>

Definition and Usage

The stat() function provides information about a file.

Note: The output may vary depending on the server, with the array possibly including the index for the number, the name, or both.

 

Note: The results are cached. Use clearstatcache() to clear the cache.

Syntax

stat(filename)

Parameter Values

 

Parameter

Description

filename

Required. Specifies the path to the file.

Technical Details

Return Value:

Returns an array with the following elements:

  • [0] or [dev]: Device number
  • [1] or [ino]: Inode number
  • [2] or [mode]: Inode protection mode
  • [3] or [nlink]: Number of links
  • [4] or [uid]: User ID of the owner
  • [5] or [gid]: Group ID of the owner
  • [6] or [rdev]: Inode device type
  • [7] or [size]: File size in bytes
  • [8] or [atime]: Last access time (as Unix timestamp)
  • [9] or [mtime]: Last modification time (as Unix timestamp)
  • [10] or [ctime]: Last inode change time (as Unix timestamp)
  • [11] or [blksize]: Block size for filesystem I/O (if supported)
  • [12] or [blocks]: Number of blocks allocated

Returns an E_WARNING on failure.

PHP Version:

4.0+