Fix & Change Folder / Files Permissions in easy way with PHP

If you are looking for code that can fix files and folder permissions in just one click here is the code to do it. Once you save it in a .php file and run it will run automatically locate the folder or directories and scan them after it will apply the give permissions to files and folders.

To use it copy the code below create a file with .php extension example ” fix.php in public_html folder or main directory of your website and open it with code editor by right click on it and paste the code and save it.

Then open the file in browser like: . Once you will open it in browser it will scan the folders and files and fix the permission by changing which you applied.


function chmod_r($dir, $dirPermissions, $filePermissions) {
  $dp = opendir($dir);
  while($file = readdir($dp)) {
    if (($file == ".") || ($file == "..")) continue;
    $fullPath = $dir. "/". $file;
    if(is_dir($fullPath)) {
      chmod($fullPath, $dirPermissions);
      chmod_r($fullPath, $dirPermissions, $filePermissions);
    } else {
      chmod($fullPath, $filePermissions);

$startDir = dirname(__FILE__);
chmod_r($startDir, 0755, 0655);

echo "All folders and files in the directory have been found and their permissions have been set.";


Explore Lvato, The Most Popular

” Digital assets In The World And Sevices ”

Related Articles

Al Qalb – Promise Land: Unity Thrives by AbdulRehman

القلب - وعدہ شدہ سرزمین: اتحاد پروان چڑھتا ہے۔ ایک زمانے میں، ایک خوبصورت سرزمین کے قلب میں آباد، القلب نامی جگہ موجود تھی۔ یہ ایک ایسی سرزمین تھی جہاں مختلف مذاہب اور عقائد کے لوگ ہم آہنگی اور اتحاد کے ساتھ رہتے تھے، اپنے تنوع کو پسند کرتے تھے اور اپنی مشترکہ انسانیت...

Web Hosting in Pakistan: Lvato Provides Hosting for Business

Web Hosting in Pakistan: Provides Affordable Solutions for Businesses of All Sizes Web hosting is a critical component of building an online presence, especially for businesses in today's digital age. It refers to the service that enables individuals or...

Unlock WinRar File Using .RAR Unlocker

Hi, Guys If you want to Unlock Files you can use our free Rar Unlocker to Unlock your.rar file Unlocking a .rar file may seem like an impossible task, but I have actually worked quite simply if you follow these steps you can unlock the file which has a numeric...