Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

Getting file information with PHP

we can read a file’s metadata for example, permissions and ownership with PHP’s stat() function, Which returns information about a file in a array format.

stat() returns associative array with information about file. see the below list

NOTE : To force PHP to reload the file’s metadata, call clearstatcache( ), which flushes PHP’s cached information.

stat() result format
Numeric Associative Description
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 **


    echo "File type: ." . substr(strrchr( $file, "."), 1) . "
"; echo "Filesize: " . round(( $fileinfo[ "size" ] / 1024 ), 1) . "k
"; // size in bytes echo "Last accessed: " . date("H:i:s, d/m/y", $fileinfo["atime"]) . "
"; // time of last access (Unix timestamp) echo "Last Modified: " . date("H:i:s, d/m/y", $fileinfo["mtime"]); // time of last modification (Unix timestamp) ?>

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments