【php实现验证码】PHP脚本实现Magento权限设置与缓存清理

更新时间:2017-10-11    来源:magento    手机版     字体:

【www.bbyears.com--magento】

 代码如下

## 设置文件644,目录755
function AllDirChmod( $dir = "./", $dirModes = 0755, $fileModes = 0644 ){
   $d = new RecursiveDirectoryIterator( $dir );
   foreach( new RecursiveIteratorIterator( $d, 1 ) as $path ){
      if( $path->isDir() ) chmod( $path, $dirModes );
      else if( is_file( $path ) ) chmod( $path, $fileModes );
  }
}

## 清除指定目录
function cleandir($dir) {
    if ($handle = opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != ".." && is_file($dir."/".$file)) {
                if (unlink($dir."/".$file)) { }
                else { echo $dir . "/" . $file . " (file) NOT deleted!
"; }
            }
            else if ($file != "." && $file != ".." && is_dir($dir."/".$file)) {
                cleandir($dir."/".$file);
                if (rmdir($dir."/".$file)) { }
                else { echo $dir . "/" . $file . " (directory) NOT deleted!
"; }
            }
        }
        closedir($handle);
    }
}

## 判断目录是否为空
function isDirEmpty($dir){
     return (($files = @scandir($dir)) && count($files) <= 2);
}

echo "----------------------- CLEANUP START -------------------------
";
$start = (float) array_sum(explode(" ",microtime()));
echo "
*************** SETTING PERMISSIONS ***************
";
echo "Setting all folder permissions to 755
";
echo "Setting all file permissions to 644
";
AllDirChmod( "." );
echo "Setting pear permissions to 550
";
chmod("pear", 550);

echo "
****************** CLEARING CACHE ******************
";

if (file_exists("var/cache")) {
    echo "Clearing var/cache
";
    cleandir("var/cache");
}

if (file_exists("var/session")) {
    echo "Clearing var/session
";
    cleandir("var/session");
}

if (file_exists("var/minifycache")) {
    echo "Clearing var/minifycache
";
    cleandir("var/minifycache");
}

if (file_exists("downloader/pearlib/cache")) {
    echo "Clearing downloader/pearlib/cache
";
    cleandir("downloader/pearlib/cache");
}

if (file_exists("downloader/pearlib/download")) {
    echo "Clearing downloader/pearlib/download
";
    cleandir("downloader/pearlib/download");
}

if (file_exists("downloader/pearlib/pear.ini")) {
    echo "Removing downloader/pearlib/pear.ini
";
    unlink ("downloader/pearlib/pear.ini");
}

echo "
************** CHECKING FOR EXTENSIONS ***********
";
If (!isDirEmpty("app/code/local/")) {
    echo "-= WARNING =- Overrides or extensions exist in the app/code/local folder
";
}
If (!isDirEmpty("app/code/community/")) {
    echo "-= WARNING =- Overrides or extensions exist in the app/code/community folder
";
}
$end = (float) array_sum(explode(" ",microtime()));
echo "
------------------- CLEANUP COMPLETED in:". sprintf("%.4f", ($end-$start))." seconds ------------------
";
?>

本文来源:http://www.bbyears.com/wangyezhizuo/36222.html