Recursive chmod with PHP


/ Published in: PHP
Save to your folder(s)

I use it when i've problems with permissions of user-uploaded files.


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. function chmod_R($path, $filemode) {
  4.  
  5. $dh = opendir($path);
  6. while ($file = readdir($dh)) {
  7. if($file != '.' && $file != '..') {
  8. $fullpath = $path.'/'.$file;
  9. echo 'chmod ' .$filemode.' '.$fullpath. "<br />";
  10. chmod($fullpath, $filemode);
  11. echo '<br />';
  12. if(is_dir($fullpath)) {
  13.  
  14. chmod_R($fullpath, $filemode);
  15.  
  16. }
  17. }
  18. }
  19.  
  20. closedir($dh);
  21. }
  22.  
  23. chmod_R('.', 0755);
  24. ?>

URL: recursive-chmod-php

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.