PHP Tutorial - PHP fileperms() Function






Definition

The fileperms() function returns the permissions for a file or directory.

Syntax

PHP fileperms() Function has the following syntax.

fileperms(filename)

Parameter

ParameterIs requiredDescription
filenameRequired.File to check

Return

This function returns the permission as a number on success or FALSE on failure.

Note

The result of this function are cached. Use clearstatcache() to clear the cache.





Example 1

Get the file permission


<?php
echo fileperms("test.txt");
?>

The code above generates the following result.

Example 2

Display permissions as an octal value:


<?php
echo substr(sprintf("%o",fileperms("test.txt")),-4);
?>

The code above generates the following result.