Пример #1
0
 public function backdropUpload(BackdropEntityAware $entity, BackdropUploadStrategy $strategy, string $textColor, string $tmpFile) : UploadedBackdrop
 {
     $this->validateFile($strategy, $tmpFile);
     $uid = join('/', str_split($entity->getSID(), 2));
     $fileName = GenerateRandomString::gen(8) . '_' . FileNameFilter::filter(basename($tmpFile));
     $storagePath = sprintf('%s/%s/%s', $strategy->getStoragePath(), $uid, $fileName);
     $publicPath = sprintf('%s/%s/%s', $strategy->getPublicPath(), $uid, $fileName);
     $strategy->getFileSystem()->write($fileName, $tmpFile);
     $backdrop = new UploadedBackdrop($storagePath, $publicPath, $textColor);
     $entity->setBackdrop($backdrop);
     return $backdrop;
 }
Пример #2
0
 public function uploadAttachment(string $tmpFile, string $desiredFileName) : Attachment
 {
     $desiredFileName = FileNameFilter::filter($desiredFileName);
     $attachmentType = $this->factoryFileAttachmentType($tmpFile);
     if ($attachmentType instanceof FileAttachmentType) {
         $this->validateFileSize($tmpFile, $attachmentType);
     }
     $subDirectory = join('/', str_split(GenerateRandomString::gen(12), 2));
     $storagePath = $subDirectory . '/' . $desiredFileName;
     $publicPath = sprintf('%s/%s/%s', $this->wwwDir, $subDirectory, $desiredFileName);
     $finfo = new \finfo(FILEINFO_MIME);
     $content = file_get_contents($tmpFile);
     $contentType = $finfo->buffer($content);
     if ($this->fileSystem->write($storagePath, $content) === false) {
         throw new \Exception('Failed to copy uploaded file');
     }
     $result = new Result($publicPath, $content, $contentType);
     $source = new LocalSource($publicPath, $storagePath);
     return $this->linkAttachment($publicPath, $subDirectory, $desiredFileName, $result, $source);
 }