How do I chmod a directory and all files in it???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

How do I chmod a directory and all files in it???

Post by Maluendaster »

How do I chmod a directory and all files in it??

For example, I want to chmod de dir images, and all files in it, and also i want to chmod the dir logs and all files in it... and also, that the script tells me if it was chmoded or not....

thank you...

PD : I looked http://cl.php.net/chmod , and i didn't find the code I need.....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

build a file and directory list, run said list through chmod one-by-one.
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Post by Maluendaster »

i don't understand you, please keep in mind that i'm into PHP for a very short time.... :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  1. build an array containing all the file names and directory names you want to chmod. opendir()-readdir() and glob() can help here.
  2. use a loop control to iterate over this array calling chmod for each and every entry you've created.
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Post by Maluendaster »

feyd wrote:
  1. build an array containing all the file names and directory names you want to chmod. opendir()-readdir() and glob() can help here.
  2. use a loop control to iterate over this array calling chmod for each and every entry you've created.
thanks, i'm gonna try that and see if i can make it work....
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Ok just some FYI, and I am sorry I don't have time to look this up, but there are *ix commands that can be run from a shell that will recursivly apply chmod permissions respective of folders vs files. Might want to search on google for a while.
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Post by Maluendaster »

agtlewis wrote:Ok just some FYI, and I am sorry I don't have time to look this up, but there are *ix commands that can be run from a shell that will recursivly apply chmod permissions respective of folders vs files. Might want to search on google for a while.
yeah i know, but what i want to do, is a scritp that automaticly chmod the dirs and files (like setup.php or something), because i need to install this script several times...
User avatar
themurph
Forum Commoner
Posts: 76
Joined: Wed Apr 19, 2006 1:56 pm
Contact:

Post by themurph »

from php:
----------------------------------------
http://us3.php.net/chmod

Specifically, look at the post from 27-Nov-2004 01:09 in the user comments section.



from *nix prompt:
----------------------------------------
chmod -R [permissions] /path/to/directory
google for "chmod man page" for more info
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Post by Maluendaster »

themurph wrote:from php:
----------------------------------------
http://us3.php.net/chmod

Specifically, look at the post from 27-Nov-2004 01:09 in the user comments section.



from *nix prompt:
----------------------------------------
chmod -R [permissions] /path/to/directory
google for "chmod man page" for more info

thank you
Post Reply