PHP change Folder Permissions Recursively
- Article
- Comment
PHP change Folder Permissions Recursively. Sometime we have to change the complete folder file permissions. I mean, we may have to change all the file permissions in a directory. For that, we need to use the “chmod() ” php function to change. but doing it for each and every file with the following code is fuzzy work and its time consuming one.
chmod("kvcodes.txt",0777);
So, we may have to use a function to this in short way.
But we have some PhP function to do this easily. but many functions failed to provide results.
function kv_change_file_permission($folder_path) { $kv_dir = new DirectoryIterator($folder_path); foreach ($kv_dir as $single) { chmod($single->getPathname(), 0777); if ($single->isDir() && !$single->isDot()) { chmod_r($single->getPathname()); } } }
The above one is the function to change all the files and sub folder permissions directly. Use the following code to call it.
kv_change_file_permission('path/to/the/folder');
That’s it, you are done.
Check the file permissions through FTP .