/** * @param string $file */ public function addImage($file) { if (!is_uploaded_file($file['tmp_name'])) { throw new LogicException(); } if ((int) $file['size'] > self::CONTROL_IMAGE_MAX_FILE_SIZE) { throw new LogicException(); } if (!UTIL_File::validateImage($file['name'])) { throw new LogicException(); } $image = new BOL_ThemeImage(); $this->themeImageDao->save($image); $ext = UTIL_File::getExtension($file['name']); $imageName = 'theme_image_' . $image->getId() . '.' . $ext; //cloudfiles header fix for amazon : need right extension to upload file with right header $newTempName = $file['tmp_name'] . '.' . $ext; rename($file['tmp_name'], $newTempName); OW::getStorage()->copyFile($newTempName, $this->userfileImagesDir . $imageName); if (file_exists($newTempName)) { unlink($newTempName); } $image->setFilename($imageName); $this->themeImageDao->save($image); return $image; }
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; }