php: chmod recursively

zimu

Diamond Member
Jun 15, 2001
6,209
0
0
been trying to find a way to chmod a folder and all files and all subfolders etc recursively.

context: have an upload via-web interface, it accepts zip files, extracts them and maintains directory structure. want to end the script to that interface with a command that recursively goes through every folder in the working directory and every file and chmods it to something i set.

help?
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
pseudocode:

function mod(string dir, int permissions){
foreach(entry in dir){
if(entry is a directory and entry is not "." or ".."){
mod(dir + entry, permissions);
}
else{
chmod permissions dir+entry;
}
}

I don't know PHP very well, but it's a pretty damn simple recursive function.
 

Zugzwang152

Lifer
Oct 30, 2001
12,134
1
0
all you have to do is run chmod in the root folder. chmod - R 755 * i think will do what you want.
 

bersl2

Golden Member
Aug 2, 2004
1,617
0
0
find $DIR -type d -exec chmod 755 '{}' \;

The problem with chmod -R is that it also changes the files too. Though I suppose chmod -R +X $DIR may work in this situation. Do any of the files in that hierarchy have execute for some users but not others?