I want to recursively set the folder and file permissions. Folders should get 750 and files 644. I found this and made some adaptions. Would this one work?
<?php function chmod_r($Path) { $dp = opendir($Path); while($File = readdir($dp)) { if($File != "." AND $File != "..") { if(is_dir($File)){ chmod($File, 0750); }else{ chmod($Path."/".$File, 0644); if(is_dir($Path."/".$File)) { chmod_r($Path."/".$File); } } } } closedir($dp); } ?>
Use chmod -R 755 /opt/lampp/htdocs if you want to change permissions of all files and directories at once. Use find /opt/lampp/htdocs -type d -exec chmod 755 {} \; if the number of files you are using is very large.
Setting 777 permissions to a file or directory means that it will be readable, writable and executable by all users and may pose a huge security risk.
To change directory permissions for everyone, use “u” for users, “g” for group, “o” for others, and “ugo” or “a” (for all). chmod ugo+rwx foldername to give read, write, and execute to everyone. chmod a=r foldername to give only read permission for everyone.
Why don't use find tool for this?
exec ("find /path/to/folder -type d -exec chmod 0750 {} +"); exec ("find /path/to/folder -type f -exec chmod 0644 {} +");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With