In PHP, lstat() returns information about a file or a symbolic link, such as its size, owner, permissions and modification time.
It works like stat(), with one big difference: if the path is a symbolic link, lstat() describes the link itself instead of the file it points to.
Syntax
Call lstat() with the values you need. Start with this line.
PHP
$info = lstat('notes.txt');
Call
What it does
lstat('notes.txt')
Returns an array with the size, times and permissions of notes.txt.
lstat('current')['size']
Reads only the size of the item named current.
lstat('missing.txt')
Returns false with a warning because the path does not exist.
The result array has both numbered keys (0 to 12) and named keys such as size, mtime, uid, gid, mode and nlink. Use the named keys because they are much easier to read. Results are cached, so call clearstatcache() when a file changes during the same script.
Library declarations
PHP
lstat(string $filename): array|false
Parameters
Parameter
Description
filename
Required. The path of the file or symbolic link.
Return Value
Return Value
Description
array|false
Returns an array of file information on success, or false on failure.
PHP Examples
Example 1 — Read the Size of a File
Create a small file and read its size from the lstat() result.
chdir() makes the relative names refer to the current folder.
symlink() creates hello-link. txt that points to hello.txt.
stat() follows the link and reports the size of hello. txt, which is 13 bytes.
lstat() reports the link itself, whose size is the length of the stored path hello. txt, which is 9.
Frequently Asked Questions
It returns an array of information about a file or symbolic link, including size, owner, permissions and times.
stat() follows symbolic links and describes the target. lstat() describes the link itself.
It returns false and raises a warning. Check the result with === false.
Named keys include dev, ino, mode, nlink, uid, gid, rdev, size, atime, mtime, ctime, blksize and blocks. The same values are also stored under numbers 0 to 12.
PHP caches the result for the same path. Call clearstatcache() if the file may have changed.