Jan 19 2010

Recursive chmod on files and directory

Category: PhpGiulio Pons @ 10:03 am

It has happened to me that files uploaded with a small CMS cannot be downloaded with a FTP client for backup. It’s strange, and probably it was due to a bad configuration of the ftp user. This means that the user of the web is more powerful than the user of the ftp: this is not good, it’s not so safe, and if someone upload something strange you probably will not be able to notice it or even remove it.

I fixed the files with this small function that makes a recursive chmod on files and dirs:

function rchmod($dir) {
	foreach (glob("$dir/*") as $child) chmod($child, (is_dir($child)? rchmod($child): 0644));
	return 0755;
}

rchmod("./db-images");
Share

Tags: , ,