/** * Save uploaded file callback * @param UploadedFile $uploadedFile */ public function saveUploadedFileCallback($uploadedFile) { if (empty($this->_destination)) { return; } /* @var $uploadedFile UploadedFile */ $relativePath = $uploadedFile->getRelativePath(); if (empty($relativePath)) { $basePath = $this->_destination; } else { $relativePath = trim($relativePath, '/\\'); $relativePath = preg_replace('#\\/#', DIRECTORY_SEPARATOR, $relativePath); $basePath = $this->_destination . DIRECTORY_SEPARATOR . $relativePath; } if (!is_dir($basePath)) { mkdir($basePath, 0777, true); } $basePath .= DIRECTORY_SEPARATOR; foreach ($uploadedFile->getConvertedFiles() as $convertedFile) { /* @var $convertedFile ConvertedFile */ $name = $convertedFile->getName(); $path_info = pathinfo($name); $i = 2; $fullFilePath = $basePath . $name; while (file_exists($fullFilePath)) { $fullFilePath = $basePath . $path_info['filename'] . '_' . $i . '.' . $path_info['extension']; $i++; } $convertedFile->moveTo($fullFilePath); } }