Xpressengine\Storage\Storage::create PHP Méthode

create() public méthode

create file
public create ( string $content, string $path, string $name, string | null $disk = null, string | null $originId = null, Xpressengine\User\UserInterface $user = null ) : File
$content string file content
$path string directory for saved
$name string saved name
$disk string | null disk for saved
$originId string | null original file id
$user Xpressengine\User\UserInterface user instance
Résultat File
    public function create($content, $path, $name, $disk = null, $originId = null, UserInterface $user = null)
    {
        $id = $this->keygen->generate();
        $path = $this->makePath($id, $path);
        $tempFile = $this->tempFiles->create($content);
        $disk = $disk ?: $this->distributor->allot($tempFile);
        $user = $user ?: $this->auth->user();
        if (!$this->files->store($content, $path . '/' . $name, $disk)) {
            throw new WritingFailException();
        }
        $file = $this->createModel();
        $file->id = $id;
        $file->userId = $user->getId();
        $file->disk = $disk;
        $file->path = $path;
        $file->filename = $name;
        $file->clientname = $name;
        $file->mime = $tempFile->getMimeType();
        $file->size = $tempFile->getSize();
        if ($originId !== null) {
            $file->originId = $originId;
        }
        $file->save();
        $tempFile->destroy();
        return $file;
    }

Usage Example

 /**
  * Create thumbnail images
  *
  * @param string           $origin   image content
  * @param CommandInterface $command  executable command
  * @param null|string      $code     dimension code
  * @param null|string      $disk     storage disk
  * @param null|string      $path     saved path
  * @param null|string      $originId origin file id
  * @return Image
  */
 public function createThumbnails($origin, CommandInterface $command, $code = null, $disk = null, $path = null, $originId = null)
 {
     $thumbnailer = $this->makeThumbnailer();
     $content = $thumbnailer->setOrigin($origin)->addCommand($command)->generate();
     $file = $this->storage->create($content, $path ?: '', implode('_', [$command->getName(), $command->getDimension()->getWidth() . 'x' . $command->getDimension()->getHeight(), hash('sha1', $content)]), $disk, $originId);
     return $this->make($file, ['type' => $command->getName(), 'code' => $code]);
 }
All Usage Examples Of Xpressengine\Storage\Storage::create