Created
June 12, 2014 14:01
-
-
Save simonpioli/fd5409cd05f41ddaeaf4 to your computer and use it in GitHub Desktop.
Recursive PHP CHMOD Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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