Need a CHMOD script...

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
mehdi
Forum Newbie
Posts: 1
Joined: Tue Jun 10, 2003 9:22 am

Need a CHMOD script...

Post by mehdi »

I use a Linux hosting with cPanel as admin control panel. cPanel has a file decompress option. I upload all of my project files as a TAR.GZ file and decompress them in my FTP, but the problem is that the file permissions will be set to 555 when decompressing. So I can't execute them.

I need a PHP script that can set the permissions for all files and folders to simething like 777 , starting from a base folder.
Anyone can help me?
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

To chmod stuff via PHP, you need to do the following:
Manually set the base folder to 777 so that PHP can modify stuff inside of it


The below function should get you on the proper track. Warning: I have not tested it, and wrote it off the top of my head so I am not positive it works, but it should.

Code: Select all

<?php
function list_dir_contents($dir){
	if ($handle = opendir($dir)){ // open the directory
		while (false !== ($file = readdir($handle))){
			if ($file != "." && $file != ".." && !is_link($file)){
				if(is_dir($dir.$file)){
					list_dir_contents($dir.$file);  // if the file is a directory, do a recursive call
				}
				else{
					chmod($dir.$file,0777); # ftp_chmod($ftp_conn,
				}
			}
		}
		closedir($handle);
	}
         chmod($dir,0777) 
}
?>
slimsam1
Forum Commoner
Posts: 49
Joined: Wed Aug 21, 2002 12:20 am

Post by slimsam1 »

If it's a linux/unix system, just do something like...


system("chmod 777 -R dirname/");
Post Reply