UploadedFile
class UploadedFile extends File
A file uploaded through a form.
Methods
Accepts the information of the uploaded file as provided by the PHP global $_FILES.
Returns the original file name.
Returns the original file extension.
Returns the file mime type.
Returns the extension based on the client mime type.
Returns the file size.
Returns the upload error.
Returns whether the file was uploaded successfully.
Returns the maximum size of an uploaded file as configured in php.ini.
Returns an informative upload error message.
Details
at line line 88
__construct(string $path, string $originalName, string $mimeType = null, int $size = null, int $error = null, bool $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.
in File at line line 56
string|null
guessExtension()
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.
in File at line line 75
string|null
getMimeType()
Returns the mime type of the file.
The mime type is guessed using a MimeTypeGuesser instance, which uses finfo(), mimecontenttype() and the system binary "file" (in this order), depending on which of those are available.
at line line 216
File
move(string $directory, string $name = null)
Moves the file to a new location.
at line line 107
string|null
getClientOriginalName()
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.
at line line 120
string
getClientOriginalExtension()
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.
at line line 138
string|null
getClientMimeType()
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).
at line line 160
string|null
guessClientExtension()
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).
at line line 176
int|null
getClientSize()
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.
at line line 189
int
getError()
Returns the upload error.
If the upload was successful, the constant UPLOADERROK is returned. Otherwise one of the other UPLOADERRXXX constants is returned.
at line line 199
bool
isValid()
Returns whether the file was uploaded successfully.
at line line 243
static int
getMaxFilesize()
Returns the maximum size of an uploaded file as configured in php.ini.
at line line 275
string
getErrorMessage()
Returns an informative upload error message.