note 46194 added to function.fileperms

From: Date: Fri, 01 Oct 2004 19:43:27 +0000
Subject: note 46194 added to function.fileperms
Groups: php.notes 
Request: Send a blank email to php-notes+get-77701@lists.php.net to get a copy of this message
A quick function I wrote to check a file for permissions to see if it matches the $mode parameter (each mode is seperated by a coma (,): 0666,0777 <?php function check_filepermissions($file,$mode) { $modes = explode(",", $mode); foreach($modes as $perms) { if (preg_match("/".$perms."/i", substr(sprintf('%o',fileperms($file)), -4))) { return true; break; } } } ?> Can be used like so: <?php define("home",".././"); if (check_filepermissions(home."install/","0777,0666")) { correct("The file ".home."install/ has been chmodded sucsessfully"); } else { error("The file ".home."install/ has incorrect permissions, please chmod it to 0666 or 0777"); $errors++; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.fileperms.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46194 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46194&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+46194&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#77701) next »