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”

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

Recommended

The Quantcast CMP broke my sites

A javascript error in CMP blocks my site.

Maggio 19, 2023

WP Gutenberg notes

Collection of notes and thoughts on Wordpress Gutenberg blocks development.

Gennaio 9, 2023

Optimizing LCP, Largest Contentful Paint result

Notes about Core Web Vitals optimization challenge

Gennaio 4, 2023

Find values recursively inside complex json objects in PHP

A PHP function to to quickly search complex, nested php structures for specific values.

Dicembre 18, 2022

Scroll to DIV by ID without jQuery

Use scrollIntoView instead of jQuery animate.

Dicembre 16, 2022