Last active
July 21, 2021 08:55
-
-
Save dev-w3/b3909d96a679d7af1cd1bacd5d67d377 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
## 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( "." ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To change the files and directory permissions
Setup: