Example #1
0
 /**
  * 上传文件的主处理方法
  * @return mixed
  */
 private function upFile()
 {
     $file = $this->file = $_FILES[$this->fileField];
     if (!$file) {
         $this->stateInfo = $this->getStateInfo("ERROR_FILE_NOT_FOUND");
         return;
     }
     if ($this->file['error']) {
         $this->stateInfo = $this->getStateInfo($file['error']);
         return;
     } else {
         if (!file_exists($file['tmp_name'])) {
             $this->stateInfo = $this->getStateInfo("ERROR_TMP_FILE_NOT_FOUND");
             return;
         } else {
             if (!is_uploaded_file($file['tmp_name'])) {
                 $this->stateInfo = $this->getStateInfo("ERROR_TMPFILE");
                 return;
             }
         }
     }
     $this->oriName = $file['name'];
     $this->fileSize = $file['size'];
     $this->fileType = $this->getFileExt();
     $this->fullName = $this->getFullName();
     $this->filePath = $this->getFilePath();
     $this->fileName = $this->getFileName();
     $dirname = dirname($this->filePath);
     //检查文件大小是否超出限制
     if (!$this->checkSize()) {
         $this->stateInfo = $this->getStateInfo("ERROR_SIZE_EXCEED");
         return;
     }
     //检查是否不允许的文件格式
     if (!$this->checkType()) {
         $this->stateInfo = $this->getStateInfo("ERROR_TYPE_NOT_ALLOWED");
         return;
     }
     //创建目录失败
     if (!file_exists($dirname) && !mkdir($dirname, 0777, true)) {
         $this->stateInfo = $this->getStateInfo("ERROR_CREATE_DIR");
         return;
     } else {
         if (!is_writeable($dirname)) {
             $this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE");
             return;
         }
     }
     if (QN_UPLOAD_OPEN) {
         global $kekezu;
         //加载七牛类文件
         $kekezu->include_qiniu_file();
         $qn = new QiniuClass();
         $ret = $qn->upload($this->oriName, $file["tmp_name"]);
         if (!$ret) {
             $this->stateInfo = $this->getStateInfo("ERROR_QINIU_CONFIG");
             return false;
         } else {
             $url = $qn->download($ret['key']);
             $savefilename = $ret['key'];
             $urls = explode('?', $url);
             $path = $urls[0];
             $this->fullName = $path;
             $this->stateInfo = $this->stateMap[0];
             return;
         }
     }
     //移动文件
     if (!(move_uploaded_file($file["tmp_name"], $this->filePath) && file_exists($this->filePath))) {
         //移动失败
         $this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE");
     } else {
         //移动成功
         $this->stateInfo = $this->stateMap[0];
     }
     //水印
     keke_glob_class::waterMark($this->filePath);
 }
Example #2
0
            $res = $objFileT->del('file_id', $id);
            if ($res) {
                $status = 1;
                $msg = '删除成功';
            }
        }
    }
    echo json_encode(array('status' => $status, 'msg' => $msg));
    die;
} else {
    $err = 0;
    if (QN_UPLOAD_OPEN) {
        $kekezu->include_qiniu_file();
        $file = $_FILES[$filename]['name'];
        $filepath = $_FILES[$filename]['tmp_name'];
        $qn = new QiniuClass();
        $ret = $qn->upload($file, $filepath);
        if (!$ret) {
            $err = $msg = 'upload error';
            echo json_encode(array('err' => $err, 'msg' => $msg));
            die;
        } else {
            $url = $qn->download($ret['key']);
            $savefilename = $ret['key'];
            $urls = explode('?', $url);
            $path = $urls[0];
        }
    } else {
        $___y = date('Y');
        $___m = date('m');
        $___d = date('d');
Example #3
0
 function check_upload_access($access_key, $secret_key, $bucket)
 {
     self::include_qiniu_file();
     $qiniu = new QiniuClass();
     $qiniu->valid($access_key, $secret_key, $bucket);
     $token = $qiniu->uptoken();
     $filepath = S_ROOT . '/data/keke_kppw_install.lck';
     if (file_exists($filepath)) {
         $res = $qiniu->upload('keke_kppw_install', $filepath);
         if ($res['key']) {
             return $qiniu->delete($res['key']);
         }
         return false;
     } else {
         return false;
     }
 }