Recursive chmod on files and directory

It has happened to me that files uploaded with a small CMS cannot be downloaded with a FTP client for…

Gennaio 19, 2010

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");

Author

PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.

Comments on “Recursive chmod on files and directory”

There are 2 thoughts

  1. nazanin ha detto:

    Hello my friend

    It doesn’t work!

  2. admin ha detto:

    It worked for me. It could be caused from some server configuration. Maybe.

Comments are closed