Skip to content

Instantly share code, notes, and snippets.

@sarathlal-old
Created July 30, 2015 03:26
Show Gist options
  • Save sarathlal-old/78248ba89eef24f42720 to your computer and use it in GitHub Desktop.
Save sarathlal-old/78248ba89eef24f42720 to your computer and use it in GitHub Desktop.
A simple script to change folder & file permissions of Web Applications like WordPress, Magento etc.
<?php
//Put this file on the installation folder and run script via browser. This script will change all folders permission as 755 & all file's permission as 644.
//Function to set file permissions to 0644 and folder permissions to 0755
function AllDirChmod( $dir = "./", $dirModes = 0755, $fileModes = 0644 ){
$d = new RecursiveDirectoryIterator( $dir );
foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){
if( $path->isDir() ) chmod( $path, $dirModes );
else if( is_file( $path ) ) chmod( $path, $fileModes );
}
}
echo "----------------------- CLEANUP START -------------------------<br/>";
$start = (float) array_sum(explode(' ',microtime()));
echo "<br/>*************** SETTING PERMISSIONS ***************<br/>";
echo "Setting all folder permissions to 755<br/>";
echo "Setting all file permissions to 644<br/>";
AllDirChmod( "." );
$end = (float) array_sum(explode(' ',microtime()));
echo "<br/>------------ Files and folders permission changed in:". sprintf("%.4f", ($end-$start))." seconds ---------<br/>";
?>
@swissbuechi
Copy link

Works very well, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment