From d06f24b1fa3fd191a8fb47fb7aa6f01265115151 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Mon, 16 Feb 2026 14:16:37 -0500 Subject: [PATCH] upd: utils Add method to get file permissions --- src/Utils/Utils.php | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/Utils/Utils.php b/src/Utils/Utils.php index d15f4b5..f0289b1 100644 --- a/src/Utils/Utils.php +++ b/src/Utils/Utils.php @@ -32,4 +32,58 @@ class Utils // error message or try to resend the message } } + + public static function filePerms($file): string + { + $perms = fileperms($file); + + switch ($perms & 0xF000) { + case 0xC000: // socket + $info = 's'; + break; + case 0xA000: // symbolic link + $info = 'l'; + break; + case 0x8000: // regular + $info = 'r'; + break; + case 0x6000: // block special + $info = 'b'; + break; + case 0x4000: // directory + $info = 'd'; + break; + case 0x2000: // character special + $info = 'c'; + break; + case 0x1000: // FIFO pipe + $info = 'p'; + break; + default: // unknown + $info = 'u'; + } + + // Owner + $info .= (($perms & 0x0100) ? 'r' : '-'); + $info .= (($perms & 0x0080) ? 'w' : '-'); + $info .= (($perms & 0x0040) ? + (($perms & 0x0800) ? 's' : 'x' ) : + (($perms & 0x0800) ? 'S' : '-')); + + // Group + $info .= (($perms & 0x0020) ? 'r' : '-'); + $info .= (($perms & 0x0010) ? 'w' : '-'); + $info .= (($perms & 0x0008) ? + (($perms & 0x0400) ? 's' : 'x' ) : + (($perms & 0x0400) ? 'S' : '-')); + + // World + $info .= (($perms & 0x0004) ? 'r' : '-'); + $info .= (($perms & 0x0002) ? 'w' : '-'); + $info .= (($perms & 0x0001) ? + (($perms & 0x0200) ? 't' : 'x' ) : + (($perms & 0x0200) ? 'T' : '-')); + + return $info; + } }