Ejemplo n.º 1
0
 /**
  * 根据角色ID删除记录
  * 
  * @param int       $role_id        角色ID
  * @return bool
  */
 public function delByRoleId($role_id)
 {
     $this->where("roleid={$role_id}")->delete();
     del_dir($this->_cache_path);
     mk_dir($this->_cache_path, 0755);
     return true;
 }
Ejemplo n.º 2
0
/**
 * 处理$_FILES上传的文件,返回文件本地路径
 * @param string $name 上传表单名
 * @param string $UploadDir 上传子目录
 * @param boolean $datedir 是否采用分日期子目录
 * @return boolean
 */
function upload($name, $UploadDir = 'upload', $datedir = true)
{
    if (empty($_FILES) || !isset($_FILES[$name])) {
        return false;
    }
    if ($_FILES[$name]['name'] != '') {
        $file = new UploadFile();
        $file->Path = FUN_ROOT;
        $file->UploadDir = $UploadDir;
        if ($datedir) {
            $file->UploadDir .= date('/Ym');
        }
        if (!is_dir(mk_dir($file->Path . $file->UploadDir))) {
            return false;
        }
        $filename = $file->uploading($name);
        if ($file->Uploaded) {
            //$filename = basename($filename);
            return $filename;
        } else {
            print_r($file->Err);
            return false;
        }
    }
}
Ejemplo n.º 3
0
 public function init_app($user_info)
 {
     $list = $this->sql->get();
     $new_user_app = $this->config['setting_system']['new_user_app'];
     $default = explode(',', $new_user_app);
     $info = array();
     foreach ($default as $key) {
         $info[$key] = $list[$key];
     }
     $desktop = USER_PATH . $user_info['name'] . '/home/desktop/';
     mk_dir($desktop);
     foreach ($info as $key => $data) {
         if (!is_array($data)) {
             continue;
         }
         $path = iconv_system($desktop . $key . '.oexe');
         unset($data['name']);
         unset($data['desc']);
         unset($data['group']);
         file_put_contents($path, json_encode($data));
     }
     $user_info['status'] = 1;
     $member = new fileCache(USER_SYSTEM . 'member.php');
     $member->update($user_info['name'], $user_info);
 }
 public function upload($allowExts = "jpg,gif,png,jpeg", $savePath = "Upload", $other_param = array())
 {
     class_exists("UploadFile") or import("ORG.Net.UploadFile");
     $upload = new UploadFile();
     //  实例化上传类
     $upload->allowExts = explode(",", $allowExts);
     //  设置附件上传类型
     $savePath = $savePath == "/" ? "Upload" : trim($savePath, "/");
     $upload->savePath = ROOT_PATH . "/" . $savePath . "/";
     //  设置附件上传目录
     if (!is_dir($upload->savePath)) {
         mk_dir($upload->savePath);
     }
     $other_key = array("maxSize" => 3145728, "saveRule" => "uniqid", "hashType" => null, "autoCheck" => null, "uploadReplace" => null, "allowTypes" => null, "thumb" => null, "thumbMaxWidth" => null, "thumbMaxHeight" => null, "thumbPrefix" => null, "thumbSuffix" => null, "thumbPath" => null, "thumbFile" => null, "thumbRemoveOrigin" => null, "autoSub" => true, "subType" => "date", "dateFormat" => "Ym", "hashLevel" => 1);
     foreach ($other_key as $key => $val) {
         if (isset($other_param[$key])) {
             $upload->{$key} = $other_param[$key];
         } elseif ($val !== null) {
             $upload->{$key} = $val;
         }
     }
     if (!$upload->upload()) {
         //  上传错误 提示错误信息
         $result = array("status" => false, "Msg" => $upload->getErrorMsg(), "info" => null);
     } else {
         //  上传成功 获取上传文件信息
         $result = array("status" => true, "Msg" => "上传成功", "info" => $upload->getUploadFileInfo());
     }
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * 快递查询
  */
 public function detail()
 {
     $data['id'] = $_GET['id'];
     $vo = $this->db->where($data)->find();
     $this->assign('vo', $vo);
     if (!$vo) {
         $this->error('物流信息不存在');
     }
     $dir = get_dir($vo['id']);
     if (file_exists(C('DATA_CACHE_PATH') . '/delivery/' . $dir . '/list.php')) {
         $list = (include C('DATA_CACHE_PATH') . '/delivery/' . $dir . '/list.php');
     } else {
         include C('PUBLIC_INCLUDE') . "kuaidi.class.php";
         $kuaidi = new kuaidi();
         $list = $kuaidi->query($vo['shipping_code'], $vo['shipping_no']);
         krsort($list['data']);
         mk_dir(C('DATA_CACHE_PATH') . '/delivery/');
         if ($list['state'] == 3) {
             mk_dir(C('DATA_CACHE_PATH') . '/delivery/' . $dir . '/');
             F('list', $list, C('DATA_CACHE_PATH') . '/delivery/' . $dir . '/');
         }
     }
     if ($list) {
         $list['count'] = count($list['data']);
     } else {
         $list['message'] = $kuaidi->error;
     }
     if (!$list) {
         $this->error($kuaidi->getError());
     } else {
         $result['data'] = $list;
         $result['notice'] = '查询成功';
         ajaxSucReturn($result);
     }
 }
Ejemplo n.º 6
0
  private function getAccessToken() {
	$path = $this->cacheDir.'/access_token.json';
	$status = file_exists($path);
	if($status){
	  $data = json_decode(file_get_contents($path),1);
	}else{
	  mk_dir($this->cacheDir);
	}
    if ($status || $data['expire_time'] < time()) {
      $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
	  $res = json_decode($this->httpGet($url));
      $access_token = $res->access_token;
      if ($access_token) {
        $data['expire_time'] = time() + 7000;
        $data['access_token'] = $access_token;
		file_put_contents($path,json_encode($data));
		//cookie('wx_access_token',json_encode($data),7200);
        /*$fp = fopen("access_token.json", "w");
        fwrite($fp, json_encode($data));
        fclose($fp);*/
      }
    } else {
      $access_token = $data->access_token;
    }
    return $access_token;
  }
Ejemplo n.º 7
0
function copydir($source, $destination)
{
    $source = dirpath($source);
    $destination = dirpath($destination);
    $result = true;
    if (!is_dir($source)) {
        //读取源目录
        msg("源目录名称错误", 0);
    }
    if (!is_dir($destination)) {
        //读取目标目录
        if (!mk_dir($destination)) {
            msg("无法创建目标目录", 0);
        }
    }
    $handle = opendir($source);
    //取得目录的句柄
    while (($file = readdir($handle)) !== false) {
        if ($file != '.' && $file != '..') {
            $src = $source . "/" . $file;
            //源文件路径
            $dtn = $destination . "/" . $file;
            //目标文件路径
            if (is_dir($src)) {
                copydir($src, $dtn);
            } else {
                copyfile($src, $dtn);
            }
            //msg($src.'--->'.$dtn.'<br>');
        }
    }
    closedir($handle);
    return $result;
}
Ejemplo n.º 8
0
 public function _upload($module, $path, $thumb, $width, $height)
 {
     $module = $module = "" ? 'file' : $module;
     //未知模块将存入file文件夹
     switch ($module) {
         case 'img':
             $path = C(ATTACHPATH) . '/img/' . $path . '/';
             break;
         default:
             $path = C(ATTACHPATH) . '/file/' . $path . '/';
     }
     if (!is_dir($path)) {
         mk_dir($path);
     }
     import("ORG.Net.UploadFile");
     $upload = new UploadFile();
     $upload->maxSize = C(ATTACHSIZE);
     $upload->allowExts = C(ATTACHEXT);
     $upload->savePath = $path;
     $upload->saveRule = 'uniqid';
     isset($thumb) ? $upload->thumb = $thumb : ($upload->thumb = C(ATTACH));
     isset($width) ? $upload->thumbMaxWidth = $width : ($upload->thumbMaxWidth = C(THUMBMAXWIDTH));
     isset($height) ? $upload->thumbMaxHeight = $height : ($upload->thumbMaxHeight = C(THUMBMAXHEIGHT));
     $upload->thumbSuffix = C(THUMBSUFFIX);
     //$upload->thumbMaxWidth =C(THUMBMAXWIDTH);
     //$upload->thumbMaxHeight =C(THUMBMAXHEIGHT);
     if (!$upload->upload()) {
         //捕获上传异常
         return $this->error($upload->getErrorMsg());
     } else {
         //上传成功
         return $upload->getUploadFileInfo();
     }
 }
Ejemplo n.º 9
0
  /**
   * 设置缓存
   */
  public function Set(){
	  $name  = $_POST['name'];
	  $value  = json_decode($_POST['json_data'],true);
	  $expire = $_POST['expire'] ? $_POST['expire'] : C('DATA_CACHE_TIME');
	  if(C('DATA_CACHE_TYPE')=='Memcache'){
		$expire = $expire==-1 ? 0 : $expire;
		$name = $_POST['module'].':'.$_POST['name'];
	  }
	  $expire = $_POST['expire'] ? $_POST['expire'] : 0;
	  $dir = $_POST['dir'] ? $_POST['dir'] : '';
	  $options['temp'] = C('DATA_CACHE_PATH').$dir;
	  //创建目录
	  if(C('DATA_CACHE_TYPE')=='File')mk_dir(C('DATA_CACHE_PATH').$dir);
	  $options['filename'] = $name;
	  $cache = new Cache();
	  $cache =$cache->connect(C('DATA_CACHE_TYPE'),$options);
	  $cache->getInstance();
	  $result = $cache->set($name,$value,$expire);
	  if($_POST['from']=='self'){
	    return;
	  }
	  if($result){
	    $msg['error_code'] = 0;
	  }else{
	    $msg['error_code'] = 8002;
	  }
	  echo json_encode($msg);exit;
  }
Ejemplo n.º 10
0
 public function flash_upload_insert()
 {
     //dump($_FILES['Filedata']);exit;
     if (!isset($_POST['sessid'])) {
         exit;
     } else {
         session_id($_POST['sessid']);
     }
     $name = uniqid();
     $msg['ok'] = 'yes';
     $path = C('IMG_ROOT') . date('Y') . '/' . date('m') . '/' . date('d') . '/';
     mk_dir($path);
     $array = explode('.', $_FILES['Filedata']['name']);
     $type = array_pop($array);
     $up_name = array_shift($array);
     move_uploaded_file($_FILES['Filedata']['tmp_name'], $path . $name . '.' . $type);
     $msg['file_url'] = C('IMG_URL') . date('Y') . '/' . date('m') . '/' . date('d') . '/' . $name . '.' . $type;
     $msg['file_name'] = $up_name;
     $msg['text'] = '<a href="' . C('IMG_URL') . date('Y') . '/' . date('m') . '/' . date('d') . '/' . $name . '.' . $type . '" target="_blank">' . $up_name . '</a>';
     /*
     //添加附件信息
     $model = M('attachments');
     $add_data['source'] = $_POST['doaction'];
     $add_data['filename'] = $up_name;
     $add_data['title'] = $up_name;
     $add_data['type'] = $_FILES['Filedata']['type'];
     $add_data['size'] = $_FILES['Filedata']['size'];
     $add_data['filepath'] = C('IMG_URL').date('Y').'/'.date('m').'/'.date('d').'/'.$name.'.'.$type;
     $add_data['hash'] = $_POST['hash'];
     $add_data['size'] = $_FILES['Filedata']['size'];
     $add_data['user_id'] = $_SESSION[C('USER_AUTH_KEY')] ? $_SESSION[C('USER_AUTH_KEY')] : 0;
     */
     echo json_encode($msg);
     exit;
 }
Ejemplo n.º 11
0
function upload($upload, $target = './', $exts = 'jpg,gif,torrent,zip,rar,7z,doc,docx,xls,xlsx,ppt,pptx,mp3,wma,swf,flv,txt', $size = 20, $rename = '')
{
    mk_dir($target);
    if (is_array($upload['name'])) {
        $return = array();
        foreach ($upload["name"] as $k => $v) {
            if (!empty($upload['name'][$k])) {
                $ext = get_ext($upload['name'][$k]);
                if (strpos($exts, $ext) !== false && $upload['size'][$k] < $size * 1024 * 1024) {
                    $name = empty($rename) ? upload_name($ext) : upload_rename($rename, $ext);
                    if (upload_move($upload['tmp_name'][$k], $target . $name)) {
                        $return[] = $name;
                    }
                }
            }
        }
        return $return;
    } else {
        $return = '';
        if (!empty($upload['name'])) {
            $ext = get_ext($upload['name']);
            if (strpos($exts, $ext) !== false && $upload['size'] < $size * 1024 * 1024) {
                $name = empty($rename) ? upload_name($ext) : upload_rename($rename, $ext);
                if (upload_move($upload['tmp_name'], $target . $name)) {
                    $return = $name;
                }
            }
        }
    }
    return $return;
}
Ejemplo n.º 12
0
Archivo: utils.php Proyecto: kyosold/sc
function write_content_to_file_with_uid($tuid, $content)
{
    // 生成目录
    $path = DATA_PATH . "/" . $tuid . "/queue/";
    $file = "";
    $succ = FALSE;
    // hash目录
    $path .= date('Ymd') . "/";
    if (!file_exists($path)) {
        // 创建目录
        if (mk_dir($path) !== TRUE) {
            log_error('fail', 'mkdir {$path} fail');
            return "";
        }
    }
    $seq = 0;
    for ($i = 0; $i < 100; $i++, $seq++) {
        $file = $path . "/" . time() . "." . $seq;
        if (file_exists($file)) {
            continue;
        }
        $succ = file_put_contents($file, $content);
        if ($succ === FALSE) {
            continue;
        } else {
            break;
        }
    }
    $file = str_replace(DATA_PATH, DATA_HOST, $file);
    return $file;
}
Ejemplo n.º 13
0
 /**
 	 +------------------------------------------------------------------------------
 	 * 公共 文件上传方法
 	 +------------------------------------------------------------------------------
 	 * $path    string  上传路径
 	 * $maxsize int     上传文件最大值
 	 * $thumb   boolean 是否生成缩略图
 	 * $width   int     缩略图最大宽度
 	 * $height  int     缩略图最大高度
 	 * $autosub boolean 是否使用子目录保存文件
 	 +------------------------------------------------------------------------------
 */
 public function _upload($path, $thumb = false, $width, $height, $autosub = false, $maxsize)
 {
     import("ORG.Net.UploadFile");
     $upload = new UploadFile();
     isset($maxsize) ? $upload->maxSize = $maxsize : ($upload->maxSize = 1048576);
     //1M
     isset($path) ? $upload->savePath = $savepath = "./Attachments/" . $path . "/" : ($upload->savePath = "./Attachments/Others/");
     if (!is_dir($savepath)) {
         @mk_dir($savepath);
     }
     $upload->allowExts = explode(',', 'gif,png,jpg,jpeg');
     if ($thumb) {
         $upload->thumb = true;
         $upload->thumbPrefix = '';
         $upload->thumbSuffix = '_thumb';
         isset($wideh) ? $upload->thumbMaxWidth = $width : ($upload->thumbMaxWidth = "300");
         isset($height) ? $upload->thumbMaxHeight = $height : ($upload->thumbMaxHeight = "400");
     }
     if ($autosub) {
         $upload->autoSub = true;
         $upload->subType = 'date';
         $upload->saveRule = time;
         $upload->dateFormat = 'Y/m/d';
     }
     if (!$upload->upload()) {
         $this->error($upload->getErrorMsg());
     } else {
         $imginfo = $upload->getUploadFileInfo();
         $imginfo = $imginfo[0]['savename'];
     }
     return $imginfo;
 }
Ejemplo n.º 14
0
 function getSavePath()
 {
     $savePath = SITE_PATH . '/data/uploads/avatar/' . $this->uid;
     if (!file_exists($savePath)) {
         mk_dir($savePath);
     }
     return $savePath;
 }
Ejemplo n.º 15
0
function getSaveTempPath()
{
    $savePath = SITE_PATH . '/data/uploads/temp';
    if (!file_exists($savePath)) {
        mk_dir($savePath);
    }
    return $savePath;
}
Ejemplo n.º 16
0
function xoops_module_install_tadgallery(&$module)
{
    mk_dir(XOOPS_ROOT_PATH . "/uploads/tadgallery");
    mk_dir(XOOPS_ROOT_PATH . "/uploads/tadgallery/upload_pics");
    mk_dir(XOOPS_ROOT_PATH . "/uploads/tadgallery/medium");
    mk_dir(XOOPS_ROOT_PATH . "/uploads/tadgallery/small");
    //mk_dir(XOOPS_ROOT_PATH."/uploads/tadgallery/small/fb");
    mk_dir(XOOPS_ROOT_PATH . "/uploads/tadgallery/mp3");
    return true;
}
 /**
  * 循环创建目录
  */
 public static function mkdir($dir, $mode = 0777)
 {
     if (is_dir($dir) || @mkdir($dir, $mode)) {
         return true;
     }
     if (!mk_dir(dirname($dir), $mode)) {
         return false;
     }
     return @mkdir($dir, $mode);
 }
Ejemplo n.º 18
0
function buildAppDir()
{
    // 没有创建项目目录的话自动创建
    if (!is_dir(APP_PATH)) {
        mk_dir(APP_PATH, 0777);
    }
    if (is_writeable(APP_PATH)) {
        mkdirs(array(LIB_PATH, CONFIG_PATH, COMMON_PATH, LANG_PATH, CACHE_PATH, TMPL_PATH, TMPL_PATH . 'default/', LOG_PATH, TEMP_PATH, DATA_PATH, LIB_PATH . 'Model/', LIB_PATH . 'Action/'));
        // 目录安全写入
        if (!defined('BUILD_DIR_SECURE')) {
            define('BUILD_DIR_SECURE', false);
        }
        if (BUILD_DIR_SECURE) {
            if (!defined('DIR_SECURE_FILENAME')) {
                define('DIR_SECURE_FILENAME', 'index.html');
            }
            if (!defined('DIR_SECURE_CONTENT')) {
                define('DIR_SECURE_CONTENT', ' ');
            }
            // 自动写入目录安全文件
            $content = DIR_SECURE_CONTENT;
            $a = explode(',', DIR_SECURE_FILENAME);
            foreach ($a as $filename) {
                file_put_contents(LIB_PATH . $filename, $content);
                file_put_contents(LIB_PATH . 'Action/' . $filename, $content);
                file_put_contents(LIB_PATH . 'Model/' . $filename, $content);
                file_put_contents(CACHE_PATH . $filename, $content);
                file_put_contents(LANG_PATH . $filename, $content);
                file_put_contents(TEMP_PATH . $filename, $content);
                file_put_contents(TMPL_PATH . $filename, $content);
                file_put_contents(TMPL_PATH . 'default/' . $filename, $content);
                file_put_contents(DATA_PATH . $filename, $content);
                file_put_contents(COMMON_PATH . $filename, $content);
                file_put_contents(CONFIG_PATH . $filename, $content);
                file_put_contents(LOG_PATH . $filename, $content);
            }
        }
        // 写入测试Action
        if (!file_exists(LIB_PATH . 'Action/IndexAction.class.php')) {
            $content = '<?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action{
    public function index(){
        header("Content-Type:text/html; charset=utf-8");
        echo "<div style=\'font-weight:normal;color:blue;float:left;width:345px;text-align:center;border:1px solid silver;background:#E8EFFF;padding:8px;font-size:14px;font-family:Tahoma\'>^_^ Hello,欢迎使用<span style=\'font-weight:bold;color:red\'>ThinkPHP</span></div>";
    }
}
?>';
            file_put_contents(LIB_PATH . 'Action/IndexAction.class.php', $content);
        }
    } else {
        header("Content-Type:text/html; charset=utf-8");
        exit('<div style=\'font-weight:bold;float:left;width:345px;text-align:center;border:1px solid silver;background:#E8EFFF;padding:8px;color:red;font-size:14px;font-family:Tahoma\'>项目目录不可写,目录无法自动生成!<BR>请使用项目生成器或者手动生成项目目录~</div>');
    }
}
Ejemplo n.º 19
0
function buildAppDir()
{
    if (!is_dir(APP_PATH)) {
        mk_dir(APP_PATH, 0777);
    }
    if (is_writeable(APP_PATH)) {
        mkdirs(array(LIB_PATH, LIB_PATH . 'Model/', LIB_PATH . 'Action/', CONFIG_PATH, COMMON_PATH, LANG_PATH, TMPL_PATH, DATA_PATH, APP_DATA_PATH, CACHE_PATH, LOG_PATH, RUNTIME_PATH, MODEL_DATA_PATH, HTML_PATH, UPLOAD_PATH, RESOURCE_DATA_PATH));
        if (!defined('BUILD_DIR_SECURE')) {
            define('BUILD_DIR_SECURE', false);
        }
        if (BUILD_DIR_SECURE) {
            if (!defined('DIR_SECURE_FILENAME')) {
                define('DIR_SECURE_FILENAME', 'index.html');
            }
            if (!defined('DIR_SECURE_CONTENT')) {
                define('DIR_SECURE_CONTENT', ' ');
            }
            $content = DIR_SECURE_CONTENT;
            $a = explode(',', DIR_SECURE_FILENAME);
            foreach ($a as $filename) {
                file_put_contents(LIB_PATH . $filename, $content);
                file_put_contents(LIB_PATH . 'Action/' . $filename, $content);
                file_put_contents(LIB_PATH . 'Model/' . $filename, $content);
                file_put_contents(CACHE_PATH . $filename, $content);
                file_put_contents(LANG_PATH . $filename, $content);
                file_put_contents(RUNTIME_PATH . $filename, $content);
                file_put_contents(TMPL_PATH . $filename, $content);
                file_put_contents(TMPL_PATH . 'default/' . $filename, $content);
                file_put_contents(MODEL_DATA_PATH . $filename, $content);
                file_put_contents(COMMON_PATH . $filename, $content);
                file_put_contents(CONFIG_PATH . $filename, $content);
                file_put_contents(LOG_PATH . $filename, $content);
            }
        }
        if (!is_file(LIB_PATH . 'Action/IndexAction.class.php')) {
            $content = '<?php

class IndexAction extends Action
{
    public function index(){
	
	}
}

?>';
            file_put_contents(LIB_PATH . 'Action/IndexAction.class.php', $content);
        }
    } else {
        header("Content-Type:text/html; charset=utf-8");
        exit('<div style=\'font-weight:bold;float:left;width:345px;text-align:center;border:1px solid silver;background:#E8EFFF;padding:8px;color:red;font-size:14px;font-family:Tahoma\'>Project directory not writable, the directory can not be generated automatically! Please use the item <br/> generator or manually generated project directory</div>');
    }
}
Ejemplo n.º 20
0
/**
 * [mk_dir 创建级联目录]
 * @param  [string] $dir [要创建的目录]
 * @return [type]      [description]
 */
function mk_dir($dir)
{
    if (is_dir($dir)) {
        echo '目录已经存在';
        return true;
    }
    if (is_dir(dirname($dir))) {
        return mkdir($dir);
    }
    mk_dir(dirname($dir));
    echo $dir, '<br />';
    return mkdir($dir);
}
 public function run(&$content)
 {
     if (C('HTML_CACHE_ON') && defined('HTML_FILE_NAME')) {
         //静态文件写入
         // 如果开启HTML功能 检查并重写HTML文件
         // 没有模版的操作不生成静态文件
         if (!is_dir(dirname(HTML_FILE_NAME))) {
             mk_dir(dirname(HTML_FILE_NAME));
         }
         if (false === file_put_contents(HTML_FILE_NAME, $content)) {
             throw_exception(L('_CACHE_WRITE_ERROR_') . ':' . HTML_FILE_NAME);
         }
     }
 }
Ejemplo n.º 22
0
/**
 * 压缩文件为zip档案
 * 
 * zip('压缩包文件名全名',array('要压缩的文件'=>'在压缩包中的新路径'));
 * 
 * zip('test.zip',array('jquery-1.11.1.min.js'=>'js/jquery'));
 * 
 * zip('test.zip',array('jquery-1.11.1.min.js','jquery-1.8.3.min.js'));
 * 
 * zip('test.zip','jquery-1.11.1.min.js');
 * @param string $zip 要生成的zip文件名
 * @param array $files 要包含的文件
 * @return bool/string
 */
function zip($zip, $files = null)
{
    $dir = realpath(dirname($zip));
    if (is_file($zip)) {
        //echo "$zip exists,it will be overwritten\r\n<br />";
    } elseif (!is_dir($dir)) {
        if (is_dir(mk_dir($dir))) {
            die("{$dir} cannot create or unwritable");
        }
    }
    $archive = new PclZip($zip);
    $errors = array();
    $v_list = $archive->create('');
    if ($v_list == 0) {
        $errors[0] = $archive->errorInfo(true);
    }
    if ($files) {
        $files = (array) $files;
        foreach ($files as $file_key => $file_value) {
            if (is_string($file_key) && strlen($file_key)) {
                $in_zip_path = $file_value;
                $file = $file_key;
            } else {
                $in_zip_path = null;
                $file = $file_value;
            }
            //var_dump($file);
            if (file_exists($file)) {
                //var_dump($file);
                $file = realpath($file);
                $file_path = dirname($file);
                //var_dump($file_path);
                if ($in_zip_path) {
                    $v_list = $archive->add($file, PCLZIP_OPT_REMOVE_PATH, $file_path, PCLZIP_OPT_ADD_PATH, $in_zip_path);
                } else {
                    $v_list = $archive->add($file, PCLZIP_OPT_REMOVE_PATH, $file_path);
                }
                if ($v_list == 0) {
                    $errors[$file] = $archive->errorInfo(true);
                }
            }
        }
    }
    if ($errors && FUN_DEBUG) {
        echo implode("\r\n<br />", $errors) . "\r\n<br />";
    }
    return is_file($zip) ? $zip : false;
}
Ejemplo n.º 23
0
function plugin_diag_convert() {
    global $vars;

    if (!mk_dir()) {
        return 'Error(C): Fail mkdir()';
    }
    if (func_num_args() != 2) {
        return 'Error(C): The number of arguments is illegal.';
    }
    $args = func_get_args();
    $type = $args[0];
    $code = end($args);
    if ($type !== 'block' && $type !== 'nw' && $type !== 'seq' && $type !== 'act') {
        return 'Error(C): The value of the argument is illegal.';
    }

    return '<div align="center"><img src="'.get_script_uri().'?plugin=diag&type='.$type.'&code='.urlencode($code).'" /></div>';
}
 function index()
 {
     import('ORG.Util.Pclzip');
     clearstatcache();
     $url = "http://www.damicms.com/update/dami_update.zip";
     $save_path = './Public/';
     $ext_path = './Public/uptmp/';
     @mk_dir($ext_path);
     $save_file = $save_path . "uptemp.zip";
     if (!file_exists($save_file) || filemtime($save_file) < time() - 6 * 3600) {
         ob_end_flush();
         //清空浏览器缓存
         echo '准备下载升级文件包....<br>';
         ob_flush();
         flush();
         self::get_damipacket($url, $save_file);
     }
     if (file_exists($save_file)) {
         ob_end_flush();
         //清空浏览器缓存
         echo '正在解压升级文件包....<br>';
         ob_flush();
         flush();
         $archive = new PclZip($save_file);
         if ($archive->extract(PCLZIP_OPT_PATH, $ext_path) == 0) {
             die("Error : " . $archive->errorInfo(true));
         } else {
             ob_end_flush();
             //清空浏览器缓存
             echo '解压缩已经完成,准备更新文件....<br>';
             ob_flush();
             flush();
             //遍历文件并更新
             self::up_file($ext_path);
             ob_end_flush();
             //清空浏览器缓存
             echo '恭喜您,所有文件升级完毕!';
             ob_flush();
             flush();
             //删除升级文件
             @deldir($ext_path);
         }
     }
 }
Ejemplo n.º 25
0
function mk_dir($path, $lev = 1)
{
    if (is_dir($path)) {
        // 判断要创建的目录是否存在,存在直接返回ture
        echo '目录已经存在' . $path . '<br />';
        return true;
    }
    // if END
    if (is_dir(dirname($path))) {
        // 判断上级目录是否存在,存在则在该目录创建新的目录
        echo $lev . '创建了' . $path . '<br />';
        return mkdir($path);
    }
    // if END
    echo $lev . '递<br />';
    mk_dir(dirname($path), $lev + 1);
    echo $lev . '归-创建了' . $path . '<br />';
    return mkdir($path);
}
Ejemplo n.º 26
0
function newTemplate($tmplName)
{
    # before we get carried away, does this template already exist ? That would be a no-no.
    if (file_exists("../templates/{$tmplName}") && is_dir("../templates/{$tmplName}")) {
        echo "ERROR: {$tmplName} exists. Cannot create another template with same name.";
        return;
    } else {
        if (!is_dir("../templates/")) {
            mk_dir("../templates/");
        }
        mk_dir("../templates/{$tmplName}/config.php");
        if (file_exists("../templates/{$tmplName}/") && is_dir("../templates/{$tmplName}/")) {
            header('content-type: application/xhtml+xml; charset=utf-8');
            echo "<root><name>{$tmplName}</name><message>Deleted Template</message></root>";
        } else {
            echo "ERROR: Failed to create template {$tmplName}.";
        }
    }
}
Ejemplo n.º 27
0
 /**
  * Validate Upload Path
  *
  * Verifies that it is a valid upload path with proper permissions.
  *
  *
  * @return	bool
  */
 public function validate_upload_path()
 {
     if ($this->upload_path == '') {
         $this->set_error('upload_no_filepath');
         return FALSE;
     }
     if (!@is_dir($this->upload_path)) {
         // 文件夹不存在的话,自动创建
         mk_dir($this->upload_path);
         $this->upload_path = str_replace("\\", "/", @realpath($this->upload_path));
         //$this->set_error('upload_no_filepath');
         //return FALSE;
     }
     if (!is_really_writable($this->upload_path)) {
         $this->set_error('upload_not_writable');
         return FALSE;
     }
     $this->upload_path = preg_replace("/(.+?)\\/*\$/", "\\1/", $this->upload_path);
     return TRUE;
 }
Ejemplo n.º 28
0
function up()
{
    $petId = $_REQUEST['pet_id'];
    $nameType = empty($_REQUEST['name_type']) ? 0 : $_REQUEST['name_type'];
    $dirPath = ROOT . '/' . FILEPATH;
    // 文件夹路径
    $fileName = getFilename($petId);
    // 检测参数是否完成
    if (!isset($petId) || empty($petId) || !isset($_FILES['image']['name']) || empty($_FILES['image']['name'])) {
        return showReturn('上传参数错误');
    }
    if (!is_dir($dirPath)) {
        mk_dir($dirPath);
        // 文件夹不存在创建
    }
    // 上传文件
    $fileName = upload($_FILES['image'], $dirPath, 'jpg,gif,png', 5, $fileName);
    // 检测上传后文件是否存在。不存在便错误
    if (!file_exists($dirPath . $fileName)) {
        return showReturn('上传文件错误');
    }
    return showReturn('ok', TRUE, 'json', $fileName);
}
Ejemplo n.º 29
0
 /**
  * 文件上传,常用的上传方式
  *
  */
 public function index()
 {
     import("@.ORG.UploadFile");
     $upload = new UploadFile();
     $upload->maxSize = 20971520;
     // 设置附件上传大小,最大为20MB
     $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg', 'txt', 'doc', 'docx', 'csv', 'xlsx', 'xls');
     // 设置附件上传类型
     if ($_POST['app']) {
         $dir = "{$_POST['app']}/";
     }
     if ($_POST['module']) {
         $dir .= "{$_POST['module']}/";
     }
     $dir .= date('Ym');
     $upload->savePath = $_SERVER['DOCUMENT_ROOT'] . "/Public/uploads/{$dir}/";
     // 设置附件上传目录
     $upload->saveRule = 'time';
     //创建目录
     mk_dir($upload->savePath);
     if (!$upload->upload()) {
         // 上传错误提示错误信息
         echo '0';
     } else {
         // 上传成功 获取上传文件信息
         $info = $upload->getUploadFileInfo();
         // 保存上传的数据信息到数据库
         $db_uploadfile = M('uploadfile');
         $data['app'] = $_POST['app'] ? $_POST['app'] : 'Sys';
         $data['module'] = $_POST['module'] ? $_POST['module'] : 'UploadFile';
         $data['add_user_id'] = $_SESSION[C('USER_AUTH_KEY')] ? $_SESSION[C('USER_AUTH_KEY')] : $_POST['add_user_id'];
         $data['add_time'] = date('Y-m-d H:i:s');
         $data['file_path'] = "/Public/uploads/{$dir}/" . $info[0]['savename'];
         $db_uploadfile->data($data)->add();
         echo $data['file_path'];
     }
 }
Ejemplo n.º 30
0
 /** 工具 - 数据备份 **/
 public function backup()
 {
     $dir = './data/database/';
     if (is_dir($dir)) {
         if ($dh = opendir($dir)) {
             while (($filename = readdir($dh)) !== false) {
                 if ($filename != '.' && $filename != '..') {
                     if (substr($filename, strrpos($filename, '.')) == '.sql') {
                         $file = $dir . $filename;
                         $filemtime = date('Y-m-d H:i:s', filemtime($file));
                         $addtime[] = $filemtime;
                         $log[] = array('filename' => $filename, 'filesize' => formatsize(filesize($file)), 'addtime' => $filemtime, 'filepath' => C('SITE_URL') . $file);
                     }
                 }
             }
         }
     } else {
         @mk_dir($dir, 0777);
     }
     array_multisort($addtime, SORT_ASC, $log);
     $this->assign('log', $log);
     $this->assign('table', D('Database')->getTableList());
     $this->display();
 }