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…

January 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

I'm a software engineer, an everyday web developer and a maker. I usually build sites with PHP, within or without WordPress. I build Internet of Things with Arduino and ESP8266. I'm the founder of Rockit.it and Dailybest.it and I'm actually the Chief Technical Officer of Better Days web agency.

Comments on “Recursive chmod on files and directory”

2 thoughts

  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.

Comments are closed

Recommended

Count coloured cells on Google Sheets with reference

In a spreadsheet if you need to count cells based on their background you can use this code in Google…

May 22, 2020

WP doesn’t send email? try this

Snippets for sending emails with Wordpress

February 8, 2020

Two post types share the same taxonomy in WordPress

Sharing a WordPress taxonomy between two post types is useful especially if you want to create a relation between different…

November 14, 2019

MYSQL add counter in a query

Use mysql variables to create a counter in SQL, PHP code to use an SQL counter and what does the i mean in mysqli?

November 9, 2019

Modify the language attribute based on category in WordPress

How to modify the language attribute in your Wordpress theme using a specific value

November 7, 2019

WordPress Fatal error: Unknown: Cannot use output buffering in output buffering display handlers in Unknown on line 0

How I've beat the php mysterious fatal error unknown in Wordpress caused by caching plugin WP Fastest Cache