facebook

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: lvato.com/fix.php . Once you will open it in browser it will scan the folders and files and fix the permission by changing which you applied.

<?php

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);
    }
  }
  closedir($dp);
}

$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.";

?>

Related Articles

How to Choose the Right Web Hosting Plan

Choosing the right web hosting plan that fulfills your needs and fits your budget can be confusing as there are a lot of companies which claim to be the top 10 or top 5 providers. Lets see what plan you should use for your website. Defining needs for the website? As...

Make Website Speed Faster and Improve Performance

Website speed is a critical factor in delivering a great user experience and improving your website's overall performance. A fast website not only helps in reducing bounce rates but also boosts your SEO rankings, improves conversion rates, and enhances customer...

Build Your Private AI like ChatGpt with Ollama: A Step by Step Guide

Have you ever wanted to create your own private AI, like ChatGPT, to ensure and keep your chat with AI private and secure? With new advancements in AI technology, it is now possible to create and run AI models locally on your machine/desktop. In this article, we will...