hi guys,
Sorry to bother again but im running out of ideas and reading the php.net and this forums didnt help me that much…
I want a function to chmod a bunch of files and folders that I regularly need to chmod (and very often forget about some of these…)
So, im getting ‘Operation not permitted’ and ‘file not found’, although im sure the files/folders are there…
Here comes my code, I know echoing everything is not the better way but it is just for debugging…
[code=php]
//This array to include all the files and folders to chmod
$ToChMod = array(
‘admin/’,
);
function MyChmod($item, $mode=’0777′)
{
// This function gets an $item to be chmoded to $mode, if no $mode is specified then
// the default is 0777
// It checks if the $item is an array and changes all the values in it
// This function excludes the . and .. resulting of the directory structure
// Possible inputs: a Directory, a File or an Array. If its a directory or a file
// then it is handled just the same
$output=”;
$path_parts = pathinfo(‘chmod.php’);
$PathToHere = getcwd();//’/home/mg46/public_html’;//pathinfo($_SERVER[‘PHP_SELF’]);
echo $PathToHere.'<br><br>’;
if(!is_array($item))
{
chmod($PathToHere.$item,$mode);
}//if is not array
else
{
// then it is an array
foreach($item as $index)
{
$changed=TRUE;
if($index != ‘.’ && $index!=’..’)
{
echo $index.'<br>’;
chmod($path_parts.$index,$mode) or ($changed=FALSE);
}
if($changed==TRUE){$output.=$index.’ changed to ‘.$mode.'<br>’;}
if($changed==FALSE){$output.=$index.’ was <b>not</b> changed <br>’;}
}
}
echo $output;
return $output;
}//function
if(chmod(__FILE__,0777)){echo ‘Changed<br>’;}
else {echo ‘Not changed<br>’;}
// __FILE__;//pathinfo($_SERVER[‘PHP_SELF’]).'<br>’;
echo getcwd().’ <<<<br><br><br>’;
MyChmod($ToChMod);
I cant even get to chmod the own running script…
So whatever suggestion you may have it will be very welcome ?
thank you