Skip to content

Instantly share code, notes, and snippets.

@pravdomil
Last active December 8, 2015 10:25
Show Gist options
  • Save pravdomil/9260ffa25dcd69341984 to your computer and use it in GitHub Desktop.
Save pravdomil/9260ffa25dcd69341984 to your computer and use it in GitHub Desktop.
Changes permissions on files and directories
<?
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