Page 1 of 1

Need a CHMOD script...

Posted: Tue Jun 10, 2003 9:22 am
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?

Posted: Tue Jun 10, 2003 11:49 am
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) 
}
?>

Posted: Tue Jun 10, 2003 6:14 pm
by slimsam1
If it's a linux/unix system, just do something like...


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