public function save($tempPath, $fileName, $version, $storageOption = null)
{
$this->storageOption = new stdClass();
if ($storageOption) {
$oldStorageOption = json_decode($storageOption);
$segment = $oldStorageOption->segment;
} else {
$segment = sprintf('%0' . strlen($this->segments) . 'd', rand(1, $this->segments));
}
$segmentPath = $this->uploadPath . '/' . $segment;
$fileName = $this->getUniqueFileName($segmentPath, $fileName);
$filePath = $this->getPathByFolderAndFileName($segmentPath, $fileName);
$this->logger->debug('Check FilePath: ' . $filePath);
if (!$this->filesystem->exists($segmentPath)) {
$this->logger->debug('Try Create Folder: ' . $segmentPath);
$this->filesystem->mkdir($segmentPath, 0777);
}
$this->logger->debug('Try to copy File "' . $tempPath . '" to "' . $filePath . '"');
if ($this->filesystem->exists($filePath)) {
throw new FilenameAlreadyExistsException($filePath);
}
$this->filesystem->copy($tempPath, $filePath);
$this->addStorageOption('segment', $segment);
$this->addStorageOption('fileName', $fileName);
return json_encode($this->storageOption);
}