Esempio n. 1
0
function zip($file, $zipfile = "", $basedir = "")
{
    $zip = new MyZip();
    $res = false;
    MakeDir(dirname($zipfile));
    if (is_dir($file)) {
        if (empty($zipfile)) {
            $zipfile = basename(rtrim($file, '/')) . ".zip";
        }
        $res = $zip->open($zipfile, ZIPARCHIVE::CREATE);
        if ($res === TRUE) {
            $zip->addDir($file);
            $zip->close();
        }
    } elseif (is_file($file)) {
        if (empty($zipfile)) {
            $zipfile = str_replace(pathinfo($file, PATHINFO_EXTENSION), "zip", basename($file));
        }
        $res = $zip->open($zipfile, ZIPARCHIVE::CREATE);
        if ($res === TRUE) {
            $zip->addFile($file);
            $zip->close();
        }
    } elseif (is_array($file)) {
        if (empty($zipfile)) {
            $zipfile = tempnam(dirname($_SERVER['PHP_SELF']), "") . ".zip";
        }
        $res = $zip->open($zipfile, ZIPARCHIVE::CREATE);
        if ($res === TRUE) {
            foreach ($file as $theFile) {
                if (is_dir($theFile)) {
                    $zip->addDir($theFile);
                } elseif (is_file($theFile)) {
                    $zip->addFile($theFile);
                }
            }
            $zip->close();
        }
    }
    if (empty($basedir)) {
        $basedir = dirname($zipfile) . "/";
    }
    if ($res) {
        $zip->open($zipfile);
        for ($i = 0; $i < $zip->numFiles; $i++) {
            $theName = $zip->getNameIndex($i);
            $newName = str_replace($basedir, "", $theName);
            $newName = preg_replace("/\\/+/", "/", $newName);
            $zip->renameName($theName, $newName);
        }
        $zip->close();
    }
    return $res ? $zipfile : false;
}
Esempio n. 2
0
     break;
 case "upload":
     $log_info = $setting['language']['admin_web_template_upload'];
     if (count($_POST) > 0) {
         $path_upload = $setting['path']['upload'] . "/tmp/" . date("Ym") . "/";
         $upload = new MyUploader();
         $upload->init(ROOT_PATH . "/" . $path_upload, true);
         $upload->DoIt(false);
         if ($upload->upload_result[0]['error'] == 0) {
             $theFile = ROOT_PATH . "/" . $path_upload . "/" . $upload->upload_result[0]['new_name'];
             require ROOT_PATH . "/source/class/myzip.class.php";
             $zip = new MyZip();
             $res = $zip->open($theFile);
             if ($res === TRUE) {
                 for ($i = 0; $i < $zip->numFiles; $i++) {
                     $theName = $zip->getNameIndex($i);
                     if (stripos($theName, "images/") !== 0 && stripos($theName, "template/") !== 0 || stripos($theName, "admin") > 0 || stripos($theName, ".php") > 0) {
                         $zip->deleteIndex($i);
                     }
                 }
                 $zip->close();
                 if (unzip($theFile, ROOT_PATH) == false) {
                     showInfo($setting['language']['admin_web_template_upload_error']);
                 }
             } else {
                 showInfo($setting['language']['admin_web_template_upload_error']);
             }
         } else {
             showInfo($setting['language']['admin_web_template_upload_error']);
         }
         unset($upload);