/**
  * 控制器执行主逻辑函数
  */
 public function invoke($uri = null)
 {
     $this->setAction(MConst::CREATE_FILE);
     // 调用父类初始化函数,注册自定义的异常和错误处理逻辑
     parent::init();
     $urlManager = new MUrlManager();
     $root = $urlManager->parseRootFromUrl($uri);
     if ($root == false) {
         //支持参数模式传递上传路径
         $path = MiniHttp::getParam("path", "");
         if (empty($path)) {
             throw new MFilesException(Yii::t('api', MConst::PATH_ERROR), MConst::HTTP_CODE_411);
         }
     }
     // 初始化创建文件公共类句柄
     $createFileHandler = MFilesCommon::initMFilesCommon();
     if (count($_FILES) == 0) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . "5"), MConst::HTTP_CODE_400);
     }
     $keys = array_keys($_FILES);
     if (count($keys) != 1) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . "6"), MConst::HTTP_CODE_400);
     }
     $key = $keys[0];
     // 检查请求参数$_FILES
     if (isset($_FILES[$key]) === false) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . "7"), MConst::HTTP_CODE_400);
     }
     // 检查文件上传过程是否有错
     if ($_FILES[$key]["error"] != 0) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . "8"), MConst::HTTP_CODE_400);
     }
     $fileName = $_FILES[$key]["name"];
     $type = MiniUtil::getMimeType($fileName);
     $size = $_FILES[$key]["size"];
     $tmpName = $_FILES[$key]["tmp_name"];
     // 验证文件是否已经上传成功
     if (file_exists($tmpName) === false) {
         throw new MFilesException(Yii::t('api', MConst::INTERNAL_SERVER_ERROR), MConst::HTTP_CODE_500);
     }
     // 检查文件上传错误
     if (filesize($tmpName) != $size) {
         throw new MFilesException(Yii::t('api', "The file upload error!"), MConst::HTTP_CODE_400);
     }
     //断点文件上传
     if ($this->isBreakpointUpload()) {
         $filesController = new MFilePutController();
         $filesController->invoke($uri);
     } else {
         //完整文件上传
         $signature = MiniUtil::getFileHash($tmpName);
         // 解析路径
         $path = MiniHttp::getParam("path", "");
         $path = MiniUtil::specialWordReplace($path);
         $parentPath = dirname($path);
         $user = MUserManager::getInstance()->getCurrentUser();
         $parentFile = MiniFile::getInstance()->getByPath($parentPath);
         //如果目录存在,且该目录is_delete=1,则把目录状态删除状态修改为0
         if (!empty($parentFile) && $parentFile['is_deleted'] == 1) {
             $values = array();
             $values['is_deleted'] = false;
             MiniFile::getInstance()->updateByPath($parentPath, $values);
         } else {
             //如果是根目录,则不用新建目录
             //否则会创建文件名名称的文件夹出来,而且目标文件位于该文件夹的下面
             if (!MiniUtil::isRootPath($parentPath, $user["id"])) {
                 MiniFile::getInstance()->createFolder($parentPath, $user['id']);
             }
         }
         $createFileHandler->size = $size;
         $createFileHandler->parent_path = MUtils::convertStandardPath($parentPath);
         $createFileHandler->file_name = MiniUtil::specialWordReplace($fileName);
         $createFileHandler->root = $root;
         $createFileHandler->path = MUtils::convertStandardPath($path);
         $createFileHandler->type = $type;
         // 文件不存在,保存文件
         $createFileHandler->saveFile($tmpName, $signature, $size);
         // 保存文件meta
         $createFileHandler->saveFileMeta();
         // 处理不同端,不同返回值
         if (MUserManager::getInstance()->isWeb() === true) {
             $createFileHandler->buildWebResponse();
             return;
         }
         $createFileHandler->buildResult();
     }
 }
 /**
  * (non-PHPdoc)
  * @see MIController::invoke()
  */
 public function invoke($uri = NULL)
 {
     $this->setAction(MConst::CREATE_FILE);
     // 调用父类初始化函数,注册自定义的异常和错误处理逻辑
     parent::init();
     $hash = @$_REQUEST['hash'];
     if (empty($hash)) {
         $hash = MiniHttp::getParam("signature", "");
     }
     // 接收参数
     if (empty($hash)) {
         throw new MFilesException(Yii::t('api', MConst::PARAMS_ERROR . "Missing parameter 'hash'."), MConst::HTTP_CODE_400);
     }
     // 解析文件路径,若返回false,则错误处理
     $urlManager = new MUrlManager();
     $path = $urlManager->parsePathFromUrl($uri);
     $root = $urlManager->parseRootFromUrl($uri);
     if ($path == false || $root == false) {
         //支持参数模式传递上传路径
         $path = MiniHttp::getParam("path", "");
         $root = "miniyun";
         $this->isNewVersion = true;
         if (empty($path)) {
             throw new MFilesException(Yii::t('api', MConst::PATH_ERROR), MConst::HTTP_CODE_411);
         }
     }
     $path = MiniUtil::specialWordReplace($path);
     $pathInfo = MUtils::pathinfo_utf($path);
     $fileName = $pathInfo["basename"];
     $parentPath = $pathInfo["dirname"];
     // 检查是否在共享文件夹内, 如果在共享文件夹内,则进行权限检查
     $user = MUserManager::getInstance()->getCurrentUser();
     $userId = $user["user_id"];
     $shareFilter = MSharesFilter::init();
     if ($shareFilter->handlerCheck($userId, $path)) {
         $userId = $shareFilter->master;
         $path = $shareFilter->_path;
         $filePath = "/" . $userId . $path;
         $shareFilter->hasPermissionExecute($filePath, MPrivilege::FILE_CREATE);
     }
     // 检查版本是否存在
     if ($this->handleCheckFileVersion($hash, $fileName) == FALSE) {
         return;
     }
     $this->handler = MFilesCommon::initMFilesCommon();
     $this->handler->parent_path = MUtils::convertStandardPath($parentPath);
     $this->handler->file_name = $fileName;
     $this->handler->root = $root;
     $this->handler->path = MUtils::convertStandardPath($path);
     $this->handler->type = MiniUtil::getMimeType($fileName);
     $this->handler->size = $this->size;
     $this->handler->file_hash = $hash;
     $this->handler->version_id = $this->version_id;
     // 保存文件meta
     $this->handler->saveFileMeta();
     if (MUserManager::getInstance()->isWeb() === true) {
         $this->handler->buildWebResponse();
         return;
     }
     $this->handler->buildResult();
 }