Jump to content
xisto Community
Sign in to follow this  
snlildude87

Change Permission With Php Code code to change files and folders permissions?

Recommended Posts

As everyone know, there two ways (that I can think of) to change files' and directories' permissions. One is to change it in your cPanel's Disk Manager and the other is with an FTP client that supports chmod.Well, I'm doing something for my site that requires files to have full permissions (Execute, Write, and Read on all three groups). At first, I thought that if I made the directory 777, then every file created in that directory will be 777 as well. I'm wrong. An alternative to doing this is to change each file permission myself, but that would be too much work.So my question is: is there a way to change file permission with PHP? Like a code in PHP that would change the files' permission?Thanks in advance! :)

Share this post


Link to post
Share on other sites

you can make a php script to change all the file permissions. It is pretty easy, you just have to cycle through every file in a directory and use the chmod command. See http://us3.php.net/chmod/ for details on the codes for chmod.


$path="yourdirectory";
$dh = opendir($path);
while ($temp = readdir($dh)) {
if ($temp!='.' && $temp!='..' && $temp!='.htaccess')
chmod($temp,777);
}

you can even make a php page that has a form so you can enter the directory name via a text input field. But, that might be a security risk though...


Share this post


Link to post
Share on other sites

a php script

Change Permission With Php Code

 

Replying to no9t9

Can you share your solution or php script that changes permission? Also, is there a way that I can make a php script that changes ownership of files and folders.

 

If so, can you help me by sending or pasting the php script code that I can upload to server and try. Thank you.

 

Sumyabazar

 

-reply by Sumyabazar

Share this post


Link to post
Share on other sites
how to parse through a website? Change Permission With Php Code

I have been given a website and I need to parse through the site and get the hyperlinks in it and then go through that link and get the contents. I am planning to do the work with curl and some preg_match function and then get thehyperlinks. Now I need to save the contents in a file and then get the file and parse it separately and do the task I need. Can I anyone help me in this? I need the source code. Please do mail me tell me or get the reply here.

Thank you

-question by Sudarsan

Share this post


Link to post
Share on other sites

To create a folder and to give the permissions am sure it wil help u $oldumask = umask(0);mkdir($folder, 0766);umask($oldumask);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.