Created
February 29, 2016 10:09
-
-
Save AdamMadrzejewski/9b4975187f6781c6c63c to your computer and use it in GitHub Desktop.
PHP change directory permissions recursively on shared hostings
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 | |
file_fix_directory(dirname(__FILE__)); | |
function file_fix_directory($dir, $nomask = array('.', '..')) { | |
if (is_dir($dir)) { | |
// Try to make each directory world writable. | |
if (@chmod($dir, 0755)) { | |
echo "<p>Cambio permessi directory a 0755: " . $dir . "</p>"; | |
} | |
} | |
if (is_dir($dir) && $handle = opendir($dir)) { | |
while (false !== ($file = readdir($handle))) { | |
if (!in_array($file, $nomask) && $file[0] != '.') { | |
if (is_dir("$dir/$file")) { | |
// Recurse into subdirectories | |
file_fix_directory("$dir/$file", $nomask); | |
} | |
else { | |
$filename = "$dir/$file"; | |
// Try to make each file world writable. | |
if (@chmod($filename, 0644)) { | |
echo "<p>Cambio permessi file a 0644: " . $filename . "</p>"; | |
} | |
} | |
} | |
} | |
closedir($handle); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment