Created
May 30, 2017 00:53
-
-
Save chwnam/cb7e05acbeefc0a86acbd802d7951082 to your computer and use it in GitHub Desktop.
CHMOD recursively.
This file contains hidden or 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 | |
| header('Content-Type: text/plain'); | |
| /** | |
| * Changes permissions on files and directories within $dir and dives recursively | |
| * into found subdirectories. | |
| */ | |
| function chmod_r($dir, $dirPermissions, $filePermissions) { | |
| $dp = opendir($dir); | |
| while($file = readdir($dp)) { | |
| if (($file == ".") || ($file == "..")) | |
| continue; | |
| $fullPath = $dir."/".$file; | |
| if(is_dir($fullPath)) { | |
| echo('DIR:' . $fullPath . "\n"); | |
| chmod($fullPath, $dirPermissions); | |
| chmod_r($fullPath, $dirPermissions, $filePermissions); | |
| } else { | |
| echo('FILE:' . $fullPath . "\n"); | |
| chmod($fullPath, $filePermissions); | |
| } | |
| } | |
| closedir($dp); | |
| } | |
| chmod_r(dirname(__FILE__), 0755, 0644); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment