Last active
December 8, 2015 10:25
-
-
Save pravdomil/9260ffa25dcd69341984 to your computer and use it in GitHub Desktop.
Changes permissions on files and directories
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
<? | |
header('Content-Type: text/plain'); | |
function chmod_r($dir) | |
{ | |
$dp = opendir($dir); | |
while($file = readdir($dp)) | |
{ | |
if (($file == ".") || ($file == "..")) continue; | |
$path = $dir . "/" . $file; | |
$is_dir = is_dir($path); | |
set_perms($path, $is_dir); | |
if($is_dir) chmod_r($path); | |
} | |
closedir($dp); | |
} | |
function set_perms($file, $is_dir) | |
{ | |
$perm = substr(sprintf("%o", fileperms($file)), -4); | |
$dirPermissions = "0750"; | |
$filePermissions = "0644"; | |
if($is_dir && $perm != $dirPermissions) | |
{ | |
echo("Dir: " . $file . "\n"); | |
chmod($file, octdec($dirPermissions)); | |
} | |
else if(!$is_dir && $perm != $filePermissions) | |
{ | |
echo("File: " . $file . "\n"); | |
chmod($file, octdec($filePermissions)); | |
} | |
flush(); | |
} | |
chmod_r(dirname(__FILE__)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment