Example #1
0
function deletedir($dir)
{
    if (!($handle = @opendir($dir))) {
        //检测要打开的目录是否存在
        echo "没有该目录" . $dir;
        //die("没有该目录");
    }
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $file = $dir . DIRECTORY_SEPARATOR . $file;
            if (is_dir($file)) {
                deletedir($file);
            } else {
                if (@unlink($file)) {
                    //echo "文件删除成功<br>";
                } else {
                    echo "文件删除失败<br>";
                }
            }
        }
    }
    closedir($handle);
    if (@rmdir($dir)) {
        echo "<script>alert(\"目录删除成功\"),window.location.href=\"file.php\";</script>";
    } else {
        echo "删除失败" . $dir;
    }
}
Example #2
0
/**
 * 呵呵呵,删除当前目录所有文件(递归)
 *
 * @return void
 **/
function deletedir($dir = '')
{
    if ($dir == '') {
        $dir = realpath('.');
    }
    echo $dir;
    exit;
    //    if(!handle=@opendir($dir)){     //检测要打开目录是否存在
    //        die("没有该目录");
    //    }
    while (false !== ($file = readdir($handle))) {
        if ($file !== "." && $file !== "..") {
            //排除当前目录与父级目录
            $file = $dir . DIRECTORY_SEPARATOR . $file;
            if (is_dir($file)) {
                deletedir($file);
            } else {
                if (@unlink($file)) {
                    echo "文件<b>{$file}</b>删除成功。<br>";
                } else {
                    echo "文件<b>{$file}</b>删除失败!<br>";
                }
            }
        }
        if (@rmdir($dir)) {
            echo "目录<b>{$dir}</b>删除成功了。<br>\n";
        } else {
            echo "目录<b>{$dir}</b>删除失败!<br>\n";
        }
    }
    /**
     * 删除数据库
     *
     * @return void
     **/
    function deleteDB()
    {
        if (DB_DAMAGE === true) {
            //start
        }
    }
}
function deletedir($file)
{
    chmod($file, 0777);
    if (is_dir($file)) {
        $handle = opendir($file);
        //while($filename = readdir($handle)) {
        while (false !== ($file = readdir($handle))) {
            if ($filename != "." && $filename != "..") {
                deletedir($file . "/" . $filename);
            }
        }
        #while
        closedir($handle);
        if (@rmdir($file)) {
            return 1;
        }
    } else {
        if (@unlink($file)) {
            return 1;
        }
    }
}
    public function doUpdate()
    {
    	$cannotWrite=0;
        //if (!class_exists('ZipArchive')) {
            //$this->error('您的服务器不支持php zip扩展,请配置好此扩展再来升级', U('System/main'));
        //}
        if (!isset($_GET['ignore'])) {
            if (!is_writable(($_SERVER['DOCUMENT_ROOT'] . '/Saivi'))) {
            	$cannotWrite=1;
                $this->error('您的服务器Saivi文件夹不可写入,设置好再升级', U('System/main'));
            }
            if (!is_writable(($_SERVER['DOCUMENT_ROOT'] . '/tpl'))) {
                $this->error('您的服务器tpl文件夹不可写入,设置好再升级', U('System/main'));
            }
        }
        $now = time();
        $updateRecord = M('System_info')->order('lastsqlupdate DESC')->find();
        $key = $this->key;
        $url = ((((($this->server_url . '?act=server&key=') . $key) . '&lastversion=') . $updateRecord['version']) . '&domain=') . $this->topdomain;
        $remoteStr = @Saivi_getcontents($url);
        $rt = json_decode($remoteStr, 1);
        if (intval($rt['success']) < 1) {
            if (intval($rt['success']) == 0) {
                if (!isset($_GET['ignore'])) {
                    $this->success('检查更新了:' . $rt['msg'], U('System/doSqlUpdate'));
                } else {
                    $this->success('检查更新了:' . $rt['msg'], U('System/doSqlUpdate', array('ignore' => 1)));
                }
            } else {
                $this->error($rt['msg'], U('System/main'));
            }
        } else {
            $locationZipPath = (RUNTIME_PATH . $now) . '.zip';
            $filename = ((((($this->server_url . '?act=server&getFile=1&key=') . $key) . '&lastversion=') . $updateRecord['version']) . '&domain=') . $this->topdomain;
            file_put_contents($locationZipPath, @Saivi_getcontents($filename));
            
            //$zip = new ZipArchive();
            $zip = new PclZip($locationZipPath);
            
            
            //$rs = $zip->open($locationZipPath);
            //if ($rs !== TRUE) {
                //$this->error('解压失败!Error Code:' . $rs);
            //}
			//
			$cacheUpdateDirName='caches_upgrade'.date('Ymd',time());
			if(!file_exists(RUNTIME_PATH.$cacheUpdateDirName)) {
				@mkdir(RUNTIME_PATH.$cacheUpdateDirName,0777);
			}
			//
			$list = $zip->extract(PCLZIP_OPT_PATH,RUNTIME_PATH.$cacheUpdateDirName);
			//$zip->extractTo(RUNTIME_PATH.$cacheUpdateDirName);
			recurse_copy(RUNTIME_PATH.$cacheUpdateDirName,$_SERVER['DOCUMENT_ROOT']);
			//$zip->close();
			//delete
			if (!$cannotWrite){
				@deletedir(RUNTIME_PATH.$cacheUpdateDirName);
			}
			@unlink($locationZipPath);
            if ($rt['time']) {
                M('System_info')->where(array('version' => $updateRecord['version']))->save(array('version' => $rt['time']));
                M('Update_record')->add(array('msg' => $rt['msg'], 'time' => $rt['time'], 'type' => $rt['type']));
            }
            if (isset($_GET['ignore'])) {
                $this->success('进入下一步:' . $rt['msg'], U('System/doUpdate', array('ignore' => 1)));
            } else {
                $this->success('进入下一步:' . $rt['msg'], U('System/doUpdate'));
            }
        }
    }
Example #5
0
 public function doUpdate()
 {
     @set_time_limit(0);
     //?document_root?
     $cannotWrite = 0;
     $notSupportZip = 0;
     if (!class_exists('ZipArchive')) {
         //$this->error('您的服务器不支持php zip扩展,请配置好此扩展再来升级',U('System/main'));
         $notSupportZip = 1;
     }
     if (!isset($_GET['ignore'])) {
         if (!is_writable($_SERVER['DOCUMENT_ROOT'] . '/PigCms')) {
             $cannotWrite = 1;
             $this->error('您的服务器PigCms文件夹不可写入,设置好再升级', U('System/main'));
         }
         if (!is_writable($_SERVER['DOCUMENT_ROOT'] . '/PigCms/Lib/Action')) {
             $cannotWrite = 1;
             $this->error('您的服务器/PigCms/Lib/Action文件夹不可写入,设置好再升级', U('System/main'));
         }
         if (!is_writable($_SERVER['DOCUMENT_ROOT'] . '/tpl')) {
             $this->error('您的服务器tpl文件夹不可写入,设置好再升级', U('System/main'));
         }
         if (!is_writable($_SERVER['DOCUMENT_ROOT'] . '/tpl/User/default')) {
             $this->error('您的服务器/tpl/User/default文件夹不可写入,设置好再升级', U('System/main'));
         }
     }
     /*
     require_once('test.php');
     if (!class_exists('test')){
     $this->success('检查更新',U('System/doSqlUpdate'));
     }
     */
     //
     $now = time();
     $updateRecord = M('System_info')->order('lastsqlupdate DESC')->find();
     $key = $this->key;
     $url = $this->server_url . 'server.php?key=' . $key . '&lastversion=' . $updateRecord['version'] . '&domain=' . $this->topdomain . '&dirtype=' . $this->dirtype;
     $remoteStr = @pigcms_getcontents($url);
     //
     $rt = json_decode($remoteStr, 1);
     if (intval($rt['success']) < 1) {
         if (intval($rt['success']) == 0) {
             if (!isset($_GET['ignore'])) {
                 $this->success('继续检查更新了,不要关闭,跳是正常的' . $rt['msg'], U('System/doSqlUpdate'));
             } else {
                 $this->success('继续检查更新了,不要关闭,跳是正常的' . $rt['msg'], U('System/doSqlUpdate', array('ignore' => 1)));
             }
         } else {
             $this->success($rt['msg'], U('System/main'));
         }
     } else {
         file_put_contents(CONF_PATH . $rt['fileid'] . '.txt', json_encode($rt));
         $locationZipPath = CONF_PATH . $rt['fileid'] . '_' . $now . '.zip';
         //$filename=$this->server_url.'server.php?getFile=1&key='.$key.'&lastversion='.$updateRecord['version'].'&domain='.$this->topdomain.'&dirtype='.$this->dirtype;
         $filename = $this->server_url2 . $rt['filepath'];
         $fileStr = @pigcms_getcontents($filename);
         if (!$fileStr) {
             $fileStr = @file_get_contents($filename);
         }
         if (!$fileStr) {
             $this->error('竟然获取不到文件');
         }
         file_put_contents(CONF_PATH . $rt['fileid'] . '.txt', json_encode($rt));
         file_put_contents($locationZipPath, $fileStr);
         //
         $cacheUpdateDirName2 = 'caches_upgrade' . date('Ym', time());
         $cacheUpdateDirName = 'caches_upgrade' . date('Ymd', time()) . time();
         if ($notSupportZip) {
             $archive = new PclZip($locationZipPath);
             if ($archive->extract(PCLZIP_OPT_PATH, CONF_PATH . $cacheUpdateDirName, PCLZIP_OPT_REPLACE_NEWER) == 0) {
                 $this->error("Error : " . $archive->errorInfo(true));
             }
         } else {
             $zip = new ZipArchive();
             $rs = $zip->open($locationZipPath);
             if ($rs !== TRUE) {
                 $err = '解压失败_2!Error Code:' . $rs . '!';
                 //$this->error('解压失败_2!Error Code:'. $rs);
             }
         }
         //
         if (!file_exists(CONF_PATH . $cacheUpdateDirName)) {
             @mkdir(CONF_PATH . $cacheUpdateDirName, 0777);
             @mkdir(CONF_PATH . $cacheUpdateDirName2, 0777);
         }
         //
         if (!$notSupportZip) {
             $zip->extractTo(CONF_PATH . $cacheUpdateDirName);
             $zip->extractTo(CONF_PATH . $cacheUpdateDirName2);
             $zip->close();
         }
         recurse_copy(CONF_PATH . $cacheUpdateDirName, $_SERVER['DOCUMENT_ROOT']);
         //delete
         if (!$cannotWrite) {
             deletedir(CONF_PATH . $cacheUpdateDirName);
         }
         //@unlink($locationZipPath);
         //record to database
         if ($rt['time']) {
             M('System_info')->where(array('version' => $updateRecord['version']))->save(array('version' => $rt['time']));
             M('Update_record')->add(array('msg' => $rt['msg'], 'time' => $rt['time'], 'type' => $rt['type']));
         }
         if (isset($_GET['ignore'])) {
             $this->success($err . '进入下一步(不要关闭,等待完成,跳是正常的):' . $rt['msg'], U('System/doUpdate', array('ignore' => 1)));
         } else {
             $this->success($err . '进入下一步(不要关闭,等待完成,跳是正常的):' . $rt['msg'], U('System/doUpdate'));
         }
     }
 }
Example #6
0
 public function doUpdate()
 {
     $cannotWrite = 0;
     if (!class_exists('ZipArchive')) {
         $this->error('您的服务器不支持php zip扩展,请配置好此扩展再来升级', U('System/main'));
     }
     if (!isset($_GET['ignore'])) {
         if (!is_writable($_SERVER['DOCUMENT_ROOT'] . '/PigCms')) {
             $cannotWrite = 1;
             $this->error('您的服务器PigCms文件夹不可写入,设置好再升级', U('System/main'));
         }
         if (!is_writable($_SERVER['DOCUMENT_ROOT'] . '/PigCms/Lib/Action')) {
             $cannotWrite = 1;
             $this->error('您的服务器/PigCms/Lib/Action文件夹不可写入,设置好再升级', U('System/main'));
         }
         if (!is_writable($_SERVER['DOCUMENT_ROOT'] . '/tpl')) {
             $this->error('您的服务器tpl文件夹不可写入,设置好再升级', U('System/main'));
         }
         if (!is_writable($_SERVER['DOCUMENT_ROOT'] . '/tpl/User/default')) {
             $this->error('您的服务器/tpl/User/default文件夹不可写入,设置好再升级', U('System/main'));
         }
     }
     $now = time();
     $updateRecord = M('System_info')->order('lastsqlupdate DESC')->find();
     $key = $this->key;
     $url = $this->server_url . 'server.php?key=' . $key . '&lastversion=' . $updateRecord['version'] . '&domain=' . $this->topdomain . '&dirtype=' . $this->dirtype;
     $remoteStr = @pigcms_getcontents($url);
     $rt = json_decode($remoteStr, 1);
     if (intval($rt['success']) < 1) {
         if (intval($rt['success']) == 0) {
             if (!isset($_GET['ignore'])) {
                 $this->success('继续检查更新了,不要关闭,跳是正常的' . $rt['msg'], U('System/doSqlUpdate'));
             } else {
                 $this->success('继续检查更新了,不要关闭,跳是正常的' . $rt['msg'], U('System/doSqlUpdate', array('ignore' => 1)));
             }
         } else {
             $this->success($rt['msg'], U('System/main'));
         }
     } else {
         $locationZipPath = RUNTIME_PATH . $now . '.zip';
         $filename = $this->server_url . 'server.php?getFile=1&key=' . $key . '&lastversion=' . $updateRecord['version'] . '&domain=' . $this->topdomain . '&dirtype=' . $this->dirtype;
         @file_put_contents($locationZipPath, @pigcms_getcontents($filename));
         $zip = new ZipArchive();
         $rs = $zip->open($locationZipPath);
         if ($rs !== TRUE) {
             $this->error('解压失败_2!Error Code:' . $rs);
         }
         $cacheUpdateDirName = 'caches_upgrade' . date('Ymd', time());
         if (!file_exists(RUNTIME_PATH . $cacheUpdateDirName)) {
             @mkdir(RUNTIME_PATH . $cacheUpdateDirName, 0777);
         }
         $zip->extractTo(RUNTIME_PATH . $cacheUpdateDirName);
         recurse_copy(RUNTIME_PATH . $cacheUpdateDirName, $_SERVER['DOCUMENT_ROOT']);
         $zip->close();
         if (!$cannotWrite) {
             @deletedir(RUNTIME_PATH . $cacheUpdateDirName);
         }
         @unlink($locationZipPath);
         if ($rt['time']) {
             M('System_info')->where(array('version' => $updateRecord['version']))->save(array('version' => $rt['time']));
             M('Update_record')->add(array('msg' => $rt['msg'], 'time' => $rt['time'], 'type' => $rt['type']));
         }
         if (isset($_GET['ignore'])) {
             $this->success('进入下一步(不要关闭,等待完成,跳是正常的):' . $rt['msg'], U('System/doUpdate', array('ignore' => 1)));
         } else {
             $this->success('进入下一步(不要关闭,等待完成,跳是正常的):' . $rt['msg'], U('System/doUpdate'));
         }
     }
 }
Example #7
0
function deletedir($dirname)
{
    $result = false;
    if (!is_dir($dirname)) {
        echo " {$dirname} is not a dir!";
        exit(0);
    }
    $handle = opendir($dirname);
    //打开目录
    while (($file = readdir($handle)) !== false) {
        if ($file != '.' && $file != '..') {
            //排除"."和"."
            $dir = $dirname . DIRECTORY_SEPARATOR . $file;
            //$dir是目录时递归调用deletedir,是文件则直接删除
            is_dir($dir) ? deletedir($dir) : unlink($dir);
        }
    }
    closedir($handle);
    $result = rmdir($dirname) ? true : false;
    return $result;
}
Example #8
0
 function deletedir($directory)
 {
     if ($dir = opendir($directory)) {
         while (($file = readdir($dir)) !== false) {
             if ($file == "." || $file == "..") {
                 continue;
             }
             if (is_dir("{$directory}/{$file}")) {
                 deletedir($directory . "/" . $file);
             } else {
                 unlink($directory . "/" . $file);
             }
         }
     }
     closedir($dir);
     rmdir("{$directory}/{$file}");
 }
Example #9
0
function sc_deletedir($dir)
{
    if ($handle = opendir($dir)) {
        while (false !== ($item = readdir($handle))) {
            if ($item != "." && $item != "..") {
                if (is_dir($dir . "/" . $item)) {
                    deletedir($dir . "/" . $item);
                } else {
                    unlink($dir . "/" . $item);
                }
            }
        }
        closedir($handle);
        rmdir($dir);
    }
}