Go Back   SZONE.US Forums > Do it yourself (DIY) > Web Tips

Web Tips Tips and tricks specializing in programming languages of the web. ie. PHP, MYSQL, XHTML, CSS, etc

[PHP] CHMOD Recursive

Views:8608
Reply
Thread Tools Search this Thread Rate Thread
  #1  
Unread 05.26.07, 05:50 PM
Zachariah Boren's Avatar
Zachariah Boren Zachariah Boren is offline
Administrator
 
Join Date: 02.07
Location: Canoga Park, CA
Posts: 928
Blog Entries: 6
Images: 10075
Send a message via ICQ to Zachariah Boren Send a message via MSN to Zachariah Boren Send a message via twitter to Zachariah Boren
[PHP] CHMOD Recursive

The chmod command (abbreviated from change mode) is a shell command in Unix and Unix-like environments.

Recursively change file mode bits. For each file operand that names a directory, chmod shall change the file mode bits of the directory and all files in the file hierarchy below it.

The Code:
I had the need to change the CHMOD on a folder and 100's of sub-folders on a linux based webserver. I did not have access to a FTP program with this operation.

I hope it helps out.

Tested on:
freeBSD, Linux
PHP Code:
<?php

// Change to the path you with to CHMOD
$path ="files";

// Change to the file permission you wish to use.
$filemode ="777";

function 
chmod_R($path$filemode) {
    if (!
is_dir($path))
       return 
chmod($path$filemode);

    
$dh opendir($path);
    while (
$file readdir($dh)) {
        if(
$file != '.' && $file != '..') {
            
$fullpath $path.'/'.$file;
            if(!
is_dir($fullpath)) {
              if (!
chmod($fullpath$filemode))
                return 
FALSE;
            } else {
              if (!
chmod_R($fullpath$filemode))
                 return 
FALSE;
            }
        }
    }

    
closedir($dh);

    if(
chmod($path$filemode))
      return 
TRUE;
    else
      return 
FALSE;
}

chmod_R($path$filemode);
?>
__________________
http://www.szone.us | http://www.gzhq.net
Twitter | Facebook | My:Hacks @ vBulletin.org
Member of Kiwanis Club of Chatsworth
Reply With Quote
Reply

Tags
chmod, php, recursive

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:


Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone PHP Shoutcast Status Zachariah Boren Standalone 53 08.27.12 10:14 AM
[PHP] Check your server for GD support Zachariah Boren Web Tips 1 08.31.10 07:12 PM
function.array-merge Argument #2 is not an array in modules vbgallery.php on line 49 niceguy vBulletin 5 12.30.07 09:57 AM


All times are GMT -8. The time now is 11:13 AM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright 2007 - 20017 SZONE.US All rights reserved