How can one differentiate between directories and files when using fileperms() in PHP?

When using fileperms() in PHP to check the permissions of a file or directory, one can differentiate between directories and files by using the is_dir() function. This function can be used to determine if a given path is a directory or not, and then based on the result, appropriate actions can be taken.

$path = '/path/to/file_or_directory';

if (is_dir($path)) {
    echo 'This is a directory.';
    // additional actions for directories
} else {
    echo 'This is a file.';
    // additional actions for files
}

// Get permissions of the file or directory
$permissions = fileperms($path);
echo 'Permissions: ' . decoct($permissions);