PHP change Folder Permissions Recursively
X

Congrats, You are Subscribed to Receive Updates.

PHP change Folder Permissions Recursively


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.

before

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.

after

Check the file permissions through FTP .

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, OpenCart Theme Development, PHP, HTML, CSS, jQuery, Bootstrap development and content SEO.

Comment Below

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar

Subscribe E-mail Updates

Congrats, You are Subscribed to Receive Updates.

Advertisement

Category Posts