Posted By

ping_ch on 02/25/09


Tagged

php recursive chmod


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

umang_nine
ping_ch
vali29


Recursive chmod with PHP


 / Published in: PHP
 

URL: recursive-chmod-php

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

  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. ?>

Report this snippet  

You need to login to post a comment.