Last active
September 4, 2018 06:49
-
-
Save yuseferi/ecd34812abec0cd2e5478c6e2d124ddc to your computer and use it in GitHub Desktop.
Fix Files Directories Permissions by PHP code
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 | |
fix_file_directory_permission(dirname(__FILE__)); | |
function fix_file_directory_permission($dir, $nomask = array('.', '..')) { | |
if (is_dir($dir)) { | |
// Try to fix directories permission | |
if (@chmod($dir, 0755)) { | |
echo "<p>Permission Fixed for : " . $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 | |
fix_file_directory_permission("$dir/$file", $nomask); | |
} | |
else { | |
$filename = "$dir/$file"; | |
// Try to fix files permission | |
if (@chmod($filename, 0644)) { | |
echo "<p>Permission Fixed for : " . $filename . "</p>"; | |
} | |
} | |
} | |
} | |
closedir($handle); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment