/** * Save uploaded image ($fileInfo) and create several resized versions ($resizeProfiles) * @param array $uploadedFileInfo - data from $_FILES * @param string $imagesPath - folder to save images in * @param string $baseFileNameWithoutExtension - base file name (used as prefix for resized file name) * @param ImageVersionConfig[] $imageVersionsConfigs - set of resize settings * @return array - false: file's content type not supported | true: saved & resized * @throws ImageUtilsException */ public static function resize(array $uploadedFileInfo, $imagesPath, $baseFileNameWithoutExtension, array $imageVersionsConfigs) { $contentType = self::getContentTypeForUploadedFile($uploadedFileInfo); if (!self::isContentTypeSupported($contentType) || empty($imagesPath) || empty($baseFileNameWithoutExtension)) { throw new ImageUtilsException('Uploaded image type is not supported', 403); } if (is_dir($imagesPath)) { self::deleteExistingFiles($imagesPath, self::getFileNamesRegexp($baseFileNameWithoutExtension)); } else { Folder::add($imagesPath, 0777); } // save original file (limited by w and h) if (empty($imageVersionsConfigs[ImageVersionConfig::SOURCE_VERSION_NAME])) { $originalFileResizeConfig = self::getDefaultOriginalFileVersionConfig(); } else { $originalFileResizeConfig = $imageVersionsConfigs[ImageVersionConfig::SOURCE_VERSION_NAME]; } $originalFileName = $baseFileNameWithoutExtension . self::applyResize($uploadedFileInfo['tmp_name'], $imagesPath . $baseFileNameWithoutExtension, $originalFileResizeConfig, $contentType); @File::remove($uploadedFileInfo['tmp_name']); //< remove temp file and use original file $filesNames = array(ImageVersionConfig::SOURCE_VERSION_NAME => $originalFileName); // save other file versions foreach ($imageVersionsConfigs as $versionName => $resizeSettings) { if ($versionName !== ImageVersionConfig::SOURCE_VERSION_NAME) { $newFileName = $baseFileNameWithoutExtension . $resizeSettings->getFileNameSuffix($versionName); $ext = self::applyResize($imagesPath . $originalFileName, $imagesPath . $newFileName, $resizeSettings, $contentType); $filesNames[$versionName] = $newFileName . $ext; } } return $filesNames; }
protected function getFilePath($name, $forSqlFile = false, $forRollbackSqlFile = false) { $basePath = preg_replace('%[/\\\\]%', DIRECTORY_SEPARATOR, parent::getMigrationPath()) . DIRECTORY_SEPARATOR; if ($forSqlFile) { $basePath .= $this->sqlSubdir . DIRECTORY_SEPARATOR; if ($forRollbackSqlFile) { $basePath .= $this->sqlRollbackSubdir . DIRECTORY_SEPARATOR; } } if (!Folder::exist($basePath)) { Folder::add($basePath, 0775); } return $basePath . date('Y_m_d_His') . '_' . $name . ($forSqlFile ? '.sql' : '.php'); }