public function moveToStoreFolder() { if (empty($this->aStoreFolder)) { throw new Exception("非法的路径属性,无法依赖此路径属性创建对应的文件夹对象"); } if (!$this->aStoreFolder->exists()) { $this->aStoreFolder = $this->aStoreFolder->create(); } // 保存文件 $sSavedFile = $this->aAchiveStrategy->makeFilePath($this->arrUploadedFile); $sSavedFolderPath = $this->aStoreFolder->path() . $sSavedFile; // 创建保存目录 $aFolderOfSavedFile = new Folder($sSavedFolderPath); if (!$aFolderOfSavedFile->exists()) { if (!$aFolderOfSavedFile->create()) { throw new Exception(__CLASS__ . "的" . __METHOD__ . "在创建路径\"%s\"时出错", array($aFolderOfSavedFile->path())); } } $sFileName = $this->aAchiveStrategy->makeFilename($this->arrUploadedFile); $sSavedFullPath = $this->aStoreFolder->path() . $sSavedFile . $sFileName; move_uploaded_file($this->arrUploadedFile['tmp_name'], $sSavedFullPath); $aSavedFile = new FsFile($sSavedFullPath); $aSavedFile->setHttpUrl($this->aStoreFolder->httpUrl() . $sSavedFile . $sFileName); $this->setValue($aSavedFile); return $aSavedFile; }
public function createChildFolder($sPath, $nFlag = Folder::CREATE_DEFAULT) { if (!($nFlag & FSO::CLEAN_PATH)) { $sPath = $this->path() . '/' . $sPath; // FSO::tidyPath($sPath,true) ; } if (is_file($sPath)) { throw new Exception('试图创建folder,但由于存在同名file无法创建: %s', $sPath); } else { $aFolder = new Folder($sPath, self::CLEAN_PATH); // 如果文件不存在,且没有要求 self::CREATE_ONLY_OBJECT ,则创建之 if (!($nFlag & self::CREATE_ONLY_OBJECT) and !$aFolder->exists()) { if (!$aFolder->create($nFlag)) { throw new Exception('无法创建目录:%s', $sPath); } } } return $aFolder; }