/** * Move file from tmp path to base path * * @param string $baseTmpPath * @param string $basePath * @param string $file * @return string */ protected function _moveFileFromTmp($baseTmpPath, $basePath, $file) { if (strrpos($file, '.tmp') == strlen($file) - 4) { $file = substr($file, 0, strlen($file) - 4); } $destFile = dirname($file) . '/' . \Magento\Core\Model\File\Uploader::getNewFileName($this->getFilePath($basePath, $file)); $this->_coreFileStorageDatabase->copyFile($this->getFilePath($baseTmpPath, $file), $this->getFilePath($basePath, $destFile)); $this->_mediaDirectory->renameFile($this->getFilePath($baseTmpPath, $file), $this->getFilePath($basePath, $destFile)); return str_replace('\\', '/', $destFile); }
/** * Get filename which is not duplicated with other files in media temporary and media directories * * @param string $fileName * @param string $dispretionPath * @return string */ protected function _getNotDuplicatedFilename($fileName, $dispretionPath) { $fileMediaName = $dispretionPath . '/' . \Magento\Core\Model\File\Uploader::getNewFileName($this->_mediaConfig->getMediaPath($fileName)); $fileTmpMediaName = $dispretionPath . '/' . \Magento\Core\Model\File\Uploader::getNewFileName($this->_mediaConfig->getTmpMediaPath($fileName)); if ($fileMediaName != $fileTmpMediaName) { if ($fileMediaName != $fileName) { return $this->_getNotDuplicatedFileName($fileMediaName, $dispretionPath); } elseif ($fileTmpMediaName != $fileName) { return $this->_getNotDuplicatedFilename($fileTmpMediaName, $dispretionPath); } } return $fileMediaName; }