function FileUploadHandlerInterface::handleFileUpload

Creates a file from an upload.

Parameters

\Drupal\file\Upload\UploadedFileInterface $uploadedFile: The uploaded file object.

array $validators: The validators to run against the uploaded file.

string $destination: The destination directory.

\Drupal\Core\File\FileExists|int $fileExists: The behavior when the destination file already exists.

Return value

\Drupal\file\Upload\FileUploadResult The created file entity.

Throws

\Symfony\Component\HttpFoundation\File\Exception\FileException Thrown when a file upload error occurred and $throws is TRUE.

\Drupal\Core\File\Exception\FileWriteException Thrown when there is an error moving the file and $throws is TRUE.

\Drupal\Core\File\Exception\FileException Thrown when a file system error occurs and $throws is TRUE.

\Drupal\file\Upload\FileValidationException Thrown when file validation fails and $throws is TRUE.

\Drupal\Core\Lock\LockAcquiringException Thrown when a lock cannot be acquired.

\ValueError Thrown if $fileExists is a legacy int and not a valid value.

File

core/modules/file/src/Upload/FileUploadHandlerInterface.php, line 42

Class

FileUploadHandlerInterface
Handles validating and creating file entities from file uploads.

Namespace

Drupal\file\Upload

Code

public function handleFileUpload(UploadedFileInterface $uploadedFile, array $validators = [], string $destination = 'temporary://', $fileExists = FileExists::Replace) : FileUploadResult;

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.