Skip to content

Instantly share code, notes, and snippets.

@simonpioli
Created June 12, 2014 14:01
Show Gist options
  • Save simonpioli/fd5409cd05f41ddaeaf4 to your computer and use it in GitHub Desktop.
Save simonpioli/fd5409cd05f41ddaeaf4 to your computer and use it in GitHub Desktop.
Recursive PHP CHMOD Script
<?php
function fixPermissions($path, $filemode = 0644, $dirmode = 0775)
{
$dir = new DirectoryIterator($path);
foreach ($dir as $item) {
if (!$item->isDot() && !$item->isLink()) {
if ($item->isFile()) {
if (chmod($item->getPathname(), $filemode)) {
echo "CHMOD file ".$item->getPathname()." to ".decoct($filemode)." successful\r\n<br>";
} else {
echo "CHMOD file ".$item->getPathname()." to ".decoct($filemode)." FAILED\r\n<br>";
}
}
if ($item->isDir()) {
if (chmod($item->getPathname(), $dirmode)) {
echo "CHMOD directory ".$item->getPathname()." to ".decoct($dirmode)." successful\r\n<br>";
} else {
echo "CHMOD directory ".$item->getPathname()." to ".decoct($dirmode)." FAILED\r\n<br>";
}
fixPermissions($item->getPathname());
}
}
}
}
fixPermissions('<dir here>', filemode, dirmode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment