class UploadedFile extends File
A file uploaded through a form.
__construct(string $path, string $originalName, string $mimeType = null, int $error = null, bool $test = false) Accepts the information of the uploaded file as provided by the PHP global $_FILES. | ||
string|null | guessExtension() Returns the extension based on the mime type. | from File |
string|null | getMimeType() Returns the mime type of the file. | from File |
File | move(string $directory, string $name = null) Moves the file to a new location. | |
getTargetFile($directory, $name = null) | from File | |
string | getName(string $name) Returns locale independent base name of the given path. | from File |
string|null | getClientOriginalName() Returns the original file name. | |
string | getClientOriginalExtension() Returns the original file extension. | |
string|null | getClientMimeType() Returns the file mime type. | |
string|null | guessClientExtension() Returns the extension based on the client mime type. | |
int|null | getClientSize() deprecated Returns the file size. | |
int | getError() Returns the upload error. | |
bool | isValid() Returns whether the file was uploaded successfully. | |
static int | getMaxFilesize() Returns the maximum size of an uploaded file as configured in php.ini. | |
string | getErrorMessage() Returns an informative upload error message. |
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:
Calling any other method on an non-valid instance will cause an unpredictable result.
string | $path | The path to the file |
string | $originalName | The original file name of the uploaded file |
string | $mimeType | The type of the file as provided by PHP; null defaults to application/octet-stream |
int | $error | The error constant of the upload (one of PHP's UPLOAD_ERR_XXX constants); null defaults to UPLOAD_ERR_OK |
bool | $test | Whether the test mode is active Local files are used in test mode hence the code should not enforce HTTP uploads |
FileException | If file_uploads is disabled |
FileNotFoundException | If the file does not exist |
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.
string|null | The guessed extension or null if it cannot be guessed |
ExtensionGuesser | |
getMimeType() |
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.
string|null | The guessed mime type (e.g. "application/pdf") |
MimeTypeGuesser |
Moves the file to a new location.
string | $directory | The destination folder |
string | $name | The new file name |
File | A File object representing the new file |
FileException | if, for any reason, the file could not have been moved |
$directory | ||
$name |
Returns locale independent base name of the given path.
string | $name | The new file name |
string | containing |
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.
string|null | The original name |
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.
string | The extension |
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).
string|null | The mime type |
getMimeType() |
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).
string|null | The guessed extension or null if it cannot be guessed |
guessExtension() | |
getClientMimeType() |
deprecated
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.
int|null | The file sizes |
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.
int | The upload error |
Returns whether the file was uploaded successfully.
bool | True if the file has been uploaded with HTTP and no error occurred |
Returns the maximum size of an uploaded file as configured in php.ini.
int | The maximum size of an uploaded file in bytes |
Returns an informative upload error message.
string | The error message regarding the specified error code |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
https://api.symfony.com/4.1/Symfony/Component/HttpFoundation/File/UploadedFile.html