/**
* 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;
}