iam使用cpanel服务器运行我的wordpress文件。最近出现了问题,我的文件权限正在自动更改,因此需要一个php脚本来在用户查看网站时自动更改wordpress文件,文件夹和子文件夹的权限。
我已经尝试过这些代码:
<?php
// define a list of wordpress root folder.
$wp = array(
'cgi-bin'
);
foreach ($wp as $site)
{
echo "Processing $site ...\n";
chmod($site, 0777);
chmod($site.'/'.'wp-admin', 0777);
chmod($site.'/'.'wp-content', 0777);
chmod($site.'/'.'wp-includes', 0777);
chmod($site.'/'.'wordpress', 0777);
}
echo "Done.\n";
?>
和
<?php
/**
* Changes permissions on files and directories within $dir and dives recursively
* into found subdirectories.
*/
function chmod_r($dir, $dirPermissions, $filePermissions) {
$dp = opendir($dir);
echo "Processing...."."<br/>";
while($file = readdir($dp))
{
if (($file == ".") || ($file == ".."))
continue;
$fullPath = $dir."/".$file;
if(is_dir($fullPath))
{
echo('DIR:' . $fullPath . "\n");
chmod($fullPath, $dirPermissions);
chmod_r($fullPath, $dirPermissions, $filePermissions);
}
else
{
echo('FILE:' . $fullPath . "\n");
chmod($fullPath, $filePermissions);
}
}
closedir($dp);
echo "Done!";
}
chmod_r('cgi-bin', 0755, 0755);
?>
但是没有按我预期的那样工作,他们没有更改子文件夹的权限...