/** * Returns an instance of class. * * @return BOL_FileTemporaryDao */ public static function getInstance() { if (self::$classInstance === null) { self::$classInstance = new self(); } return self::$classInstance; }
public function moveTemporaryFile($tmpId, $title = '') { $tmp = BOL_FileTemporaryDao::getInstance()->findById($tmpId); $tmpPath = BOL_FileTemporaryService::getInstance()->getTemporaryFilePath($tmpId); if (!$tmp) { throw new LogicException(); } if (!UTIL_File::validateImage($tmp->filename)) { throw new LogicException(); } $image = new BOL_ThemeImage(); $image->addDatetime = time(); $image->title = $title; $dimensions = getimagesize($tmpPath); $image->dimensions = "{$dimensions[0]}x{$dimensions[1]}"; $image->filesize = UTIL_File::getFileSize($tmpPath); $this->themeImageDao->save($image); $ext = UTIL_File::getExtension($tmp->filename); $imageName = 'theme_image_' . $image->getId() . '.' . $ext; $newTempName = $tmp->filename . '.' . $ext; rename($tmp->filename, $newTempName); OW::getStorage()->copyFile($tmpPath, $this->userfileImagesDir . $imageName); if (file_exists($newTempName)) { unlink($newTempName); } BOL_FileTemporaryDao::getInstance()->deleteById($tmpId); $image->setFilename($imageName); $this->themeImageDao->save($image); return $image; }
/** * Get path to temporary file in file system * * @param int $id * * @return string */ public function getTemporaryFilePath($id) { $userfilesDir = OW::getPluginManager()->getPlugin('base')->getUserFilesDir(); $file = $this->fileTemporaryDao->findById($id); return $userfilesDir . self::TMP_FILE_PREFIX . $id . $file->filename; }