Helpful Information
 
 
Category: Post a PHP snippet
Check file permissions

This is great for installers. It checks the file you provided in the first statment, against the octal you want it to have. If it has incorrect permissions, the row is red, if correct permissions, it makes a green row.

Function

function check_perms($path,$perm)
{
clearstatcache();
$configmod = substr(sprintf('%o', fileperms($path)), -4);
$trcss = (($configmod != $perm) ? "background-color:#fd7a7a;" : "background-color:#91f587;");
echo "<tr style=".$trcss.">";
echo "<td style=\"border:0px;\">". $path ."</td>";
echo "<td style=\"border:0px;\">$perm</td>";
echo "<td style=\"border:0px;\">$configmod</td>";
echo "</tr>";
}


Usage

<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\" style=\"text-align:center;\">
<tr>
<th style="border:0px;"><b>File Name</b></th>
<th style="border:0px;"><b>Needed Chmod</b></th>
<th style="border:0px;"><b>Current Chmod</b></th>
</tr>
<?php
check_perms("cache","0777");
check_perms("include/keys","0777");
check_perms("backup","0777");
check_perms("uploads","0777");
check_perms("include/template","0777");
check_perms("include/user","0777");
check_perms("img","0777");
check_perms("img/avatars","0777");
?>
</table>

Hey, thanks a lot for this, can you add a button, so that when they are all green, you can proceed with the installation.

Hey, thanks a lot for this, can you add a button, so that when they are all green, you can proceed with the installation. How about trying it yourself, and asking for help on specific issues, rather than re instantiating a 3.5 year old thread?

Oh I didnt know it was old.

Anyways, I am not good at coding php myself. So what would be some steps to doing it?

this is exactly what I need for my installation.

Basicly if all files are green, means permissions are what they are supposed to be, you can procceed with installation, which a button shows up to go to the next page of installation.










privacy (GDPR)