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/Bookmark

Related posts:

  1. Recursive remove directory (RMDIR) in PHP
  2. Copying remote files on your server with PHP
  3. ASP Function to count files in a folder
  4. Calculate dir size recursively with PHP (and count files)

Tags: , ,

2 Responses to “Recursive chmod on files and directory”

  1. nazanin says:

    Hello my friend

    It doesn’t work!

  2. admin says:

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

Leave a Reply