\Symfony\Component\HttpFoundation\FileUploadedFile

A file uploaded through a form.

Summary

Methods
Properties
Constants
__construct()
guessExtension()
getMimeType()
move()
getClientOriginalName()
getClientOriginalExtension()
getClientMimeType()
guessClientExtension()
getClientSize()
getError()
isValid()
getMaxFilesize()
getErrorMessage()
No public properties found
No constants found
getTargetFile()
getName()
No protected properties found
N/A
No private methods found
$test
$originalName
$mimeType
$size
$error
N/A

Properties

$test

$test : 

Type

$originalName

$originalName : 

Type

$mimeType

$mimeType : 

Type

$size

$size : 

Type

$error

$error : 

Type

Methods

__construct()

__construct(string  $path, string  $originalName, string|null  $mimeType = null, integer|null  $size = null, integer|null  $error = null, boolean  $test = false) 

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.

Parameters

string $path

The full temporary path to the file

string $originalName

The original file name of the uploaded file

string|null $mimeType

The type of the file as provided by PHP; null defaults to application/octet-stream

integer|null $size

The file size provided by the uploader

integer|null $error

The error constant of the upload (one of PHP's UPLOAD_ERR_XXX constants); null defaults to UPLOAD_ERR_OK

boolean $test

Whether the test mode is active Local files are used in test mode hence the code should not enforce HTTP uploads

Throws

\Symfony\Component\HttpFoundation\File\Exception\FileException

If file_uploads is disabled

\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException

If the file does not exist

guessExtension()

guessExtension() : string|null

Returns the extension based on the mime type.

If the mime type is unknown, returns null.

This method uses the mime type as guessed by getMimeType() to guess the file extension.

Returns

string|null —

The guessed extension or null if it cannot be guessed

getMimeType()

getMimeType() : string|null

Returns the mime type of the file.

The mime type is guessed using a MimeTypeGuesser instance, which uses finfo(), mime_content_type() and the system binary "file" (in this order), depending on which of those are available.

Returns

string|null —

The guessed mime type (e.g. "application/pdf")

move()

move(string  $directory, string  $name = null) : \Symfony\Component\HttpFoundation\File\File

Moves the file to a new location.

Parameters

string $directory

The destination folder

string $name

The new file name

Throws

\Symfony\Component\HttpFoundation\File\Exception\FileException

if, for any reason, the file could not have been moved

Returns

\Symfony\Component\HttpFoundation\File\File

A File object representing the new file

getClientOriginalName()

getClientOriginalName() : string|null

Returns the original file name.

It is extracted from the request from which the file has been uploaded. Then it should not be considered as a safe value.

Returns

string|null —

The original name

getClientOriginalExtension()

getClientOriginalExtension() : string

Returns the original file extension.

It is extracted from the original file name that was uploaded. Then it should not be considered as a safe value.

Returns

string —

The extension

getClientMimeType()

getClientMimeType() : string|null

Returns the file mime type.

The client mime type is extracted from the request from which the file was uploaded, so it should not be considered as a safe value.

For a trusted mime type, use getMimeType() instead (which guesses the mime type based on the file content).

Returns

string|null —

The mime type

guessClientExtension()

guessClientExtension() : string|null

Returns the extension based on the client mime type.

If the mime type is unknown, returns null.

This method uses the mime type as guessed by getClientMimeType() to guess the file extension. As such, the extension returned by this method cannot be trusted.

For a trusted extension, use guessExtension() instead (which guesses the extension based on the guessed mime type for the file).

Returns

string|null —

The guessed extension or null if it cannot be guessed

getClientSize()

getClientSize() : integer|null

Returns the file size.

It is extracted from the request from which the file has been uploaded. Then it should not be considered as a safe value.

Returns

integer|null —

The file size

getError()

getError() : integer

Returns the upload error.

If the upload was successful, the constant UPLOAD_ERR_OK is returned. Otherwise one of the other UPLOAD_ERR_XXX constants is returned.

Returns

integer —

The upload error

isValid()

isValid() : boolean

Returns whether the file was uploaded successfully.

Returns

boolean —

True if the file has been uploaded with HTTP and no error occurred

getMaxFilesize()

getMaxFilesize() : integer

Returns the maximum size of an uploaded file as configured in php.ini.

Returns

integer —

The maximum size of an uploaded file in bytes

getErrorMessage()

getErrorMessage() : string

Returns an informative upload error message.

Returns

string —

The error message regarding the specified error code

getTargetFile()

getTargetFile(  $directory,   $name = null) 

Parameters

$directory
$name

getName()

getName(string  $name) : string

Returns locale independent base name of the given path.

Parameters

string $name

The new file name

Returns

string —

containing