Skip to content

Instantly share code, notes, and snippets.

@dev-w3
Last active July 21, 2021 08:55
Show Gist options
  • Save dev-w3/b3909d96a679d7af1cd1bacd5d67d377 to your computer and use it in GitHub Desktop.
Save dev-w3/b3909d96a679d7af1cd1bacd5d67d377 to your computer and use it in GitHub Desktop.
<?php
## 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 );
}
}
## Function to clean out the contents of specified directory
function isDirEmpty($dir){
return (($files = @scandir($dir)) && count($files) <= 2);
}
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( "." );
@dev-w3
Copy link
Author

dev-w3 commented Jul 21, 2021

To change the files and directory permissions
Setup:

  1. Upload the file in your root
  2. run the file to change the permissions of all files and directories

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