Author: XE Team (developers) (developers@xpressengine.com)
Esempio n. 1
0
 /**
  * create file
  *
  * @param string        $content  file content
  * @param string        $path     directory for saved
  * @param string        $name     saved name
  * @param string|null   $disk     disk for saved
  * @param string|null   $originId original file id
  * @param UserInterface $user     user instance
  * @return 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;
 }
Esempio n. 2
0
 /**
  * file content to disk storage
  *
  * @param string      $content  file content
  * @param string      $pathname be saved path and file name
  * @param string|null $disk     be saved disk name
  * @return File
  */
 public function store($content, $pathname, $disk = null)
 {
     $disk = $disk ?: $this->distributor->allot($content);
     $this->getDisk($disk)->put($pathname, $content);
     return new File(['disk' => $disk, 'pathname' => $pathname, 'mime' => $this->getMime($content), 'size' => strlen($content)]);
 }