Jump to content

How to check if a file is chmod?


red-x

Recommended Posts

<?php

function lGetFilePerms($filename) {
$sP;

$perms = fileperms($filename);
if ($perms & 0x1000) { $sP = 'p'; }	// FIFO pipe
elseif ($perms & 0x2000) { $sP = 'c'; }	// Character special
elseif ($perms & 0x4000) { $sP = 'd'; }	// Directory
elseif ($perms & 0x6000) { $sP = 'b'; }	// Block special
elseif ($perms & 0x8000) { $sP = '-'; }	// Regular
elseif ($perms & 0xA000) { $sP = 'l'; }	// Symbolic Link
elseif ($perms & 0xC000) { $sP = 's'; }	// Socket
else { $sP = 'u'; }				// UNKNOWN

// owner
$sP .= (($perms & 0x0100) ? 'r' : '-').(($perms & 0x0080) ? 'w' : '-').(($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));
// group
$sP .= (($perms & 0x0020) ? 'r' : '-').(($perms & 0x0010) ? 'w' : '-').(($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));
// world
$sP .= (($perms & 0x0004) ? 'r' : '-').(($perms & 0x0002) ? 'w' : '-').(($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));
return $sP;
} // function lGetFilePerms()

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.