public function UploadedFile::__construct

Accepts the information of the uploaded file as provided by the PHP global $_FILES.

The file object is only created when the uploaded file is valid (i.e. when the isValid() method returns true). Otherwise the only methods that could be called on an UploadedFile instance are:

  • getClientOriginalName,
  • getClientMimeType,
  • isValid,
  • getError.

Calling any other method on an non-valid instance will cause an unpredictable result.

@api

Parameters

string $path The full temporary path to the file:

string $originalName The original file name:

string $mimeType The type of the file as provided by PHP:

integer $size The file size:

integer $error The error constant of the upload (one of PHP's UPLOAD_ERR_XXX constants):

Boolean $test Whether the test mode is active:

Throws

FileException If file_uploads is disabled

FileNotFoundException If the file does not exist

Overrides File::__construct

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/File/UploadedFile.php, line 91

Class

UploadedFile
A file uploaded through a form.

Namespace

Symfony\Component\HttpFoundation\File

Code

public function __construct($path, $originalName, $mimeType = null, $size = null, $error = null, $test = false) {
  if (!ini_get('file_uploads')) {
    throw new FileException(sprintf('Unable to create UploadedFile because "file_uploads" is disabled in your php.ini file (%s)', get_cfg_var('cfg_file_path')));
  }
  $this->originalName = basename($originalName);
  $this->mimeType = $mimeType ?: 'application/octet-stream';
  $this->size = $size;
  $this->error = $error ?: UPLOAD_ERR_OK;
  $this->test = (bool) $test;
  parent::__construct($path, UPLOAD_ERR_OK === $this->error);
}