Skip to content

Instantly share code, notes, and snippets.

@technosophos
Created February 15, 2012 17:43
Show Gist options
  • Save technosophos/1837617 to your computer and use it in GitHub Desktop.
Save technosophos/1837617 to your computer and use it in GitHub Desktop.
Test File Mode (PHP)
<?php
if (count($argv) < 2) {
print "Usage: php testmode.php file [file [...]]" . PHP_EOL;
exit(1);
}
array_shift($argv);
foreach ($argv as $file) {
print "=== Testing $file" . PHP_EOL;
$stat = stat($file);
print "Raw mode: " . $stat['mode'] . PHP_EOL;
$mode = $stat['mode'];
print "Octal mode: " . decoct($mode) . PHP_EOL . PHP_EOL;
print ($mode & 0400) . " is the owner's read bit." . PHP_EOL;
print ($mode & 0040) . " is the group's read bit." . PHP_EOL;
print ($mode & 0004) . " is the other's read bit." . PHP_EOL;
print ($mode & 0200) . " is the owner's write bit." . PHP_EOL;
print ($mode & 0020) . " is the group's write bit." . PHP_EOL;
print ($mode & 0002) . " is the other's write bit." . PHP_EOL;
print PHP_EOL;
if ($mode & 0100000) {
print "This is a file." . PHP_EOL;
}
if ($mode & 040000) {
print "This is a directory." . PHP_EOL;
}
print PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment