Return to Snippet

Revision: 11955
at February 25, 2009 07:52 by ping_ch


Initial Code
<?php

function chmod_R($path, $filemode) {

    $dh = opendir($path);
    while ($file = readdir($dh)) {
        if($file != '.' && $file != '..') {
            $fullpath = $path.'/'.$file;
			echo 'chmod ' .$filemode.' '.$fullpath. "<br />";
			chmod($fullpath, $filemode);
			echo '<br />';
            if(is_dir($fullpath)) {
			  
               chmod_R($fullpath, $filemode);
			  
            } 
        }
    }
 
    closedir($dh);    
}

chmod_R('.', 0755);
?>

Initial URL
recursive-chmod-php

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

Initial Title
Recursive chmod with PHP

Initial Tags
php

Initial Language
PHP