UploadedFile
extends File
in package
A file uploaded through a form.
Tags
Table of Contents
- $error : mixed
- $mimeType : mixed
- $originalName : mixed
- $test : mixed
- __construct() : mixed
- Accepts the information of the uploaded file as provided by the PHP global $_FILES.
- getClientMimeType() : string
- Returns the file mime type.
- getClientOriginalExtension() : string
- Returns the original file extension.
- getClientOriginalName() : string
- Returns the original file name.
- getContent() : string
- getError() : int
- Returns the upload error.
- getErrorMessage() : string
- Returns an informative upload error message.
- getMaxFilesize() : int|float
- Returns the maximum size of an uploaded file as configured in php.ini.
- getMimeType() : string|null
- Returns the mime type of the file.
- guessClientExtension() : string|null
- Returns the extension based on the client mime type.
- guessExtension() : string|null
- Returns the extension based on the mime type.
- isValid() : bool
- Returns whether the file has been uploaded with HTTP and no error occurred.
- move() : File
- Moves the file to a new location.
- getName() : string
- Returns locale independent base name of the given path.
- getTargetFile() : self
- parseFilesize() : int|float
- Returns the given size from an ini value in bytes.
Properties
$error
private
mixed
$error
$mimeType
private
mixed
$mimeType
$originalName
private
mixed
$originalName
$test
private
mixed
$test
Methods
__construct()
Accepts the information of the uploaded file as provided by the PHP global $_FILES.
public
__construct(string $path, string $originalName[, string|null $mimeType = null ][, int|null $error = null ][, bool $test = false ]) : mixed
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
- $path : string
-
The full temporary path to the file
- $originalName : string
-
The original file name of the uploaded file
- $mimeType : string|null = null
-
The type of the file as provided by PHP; null defaults to application/octet-stream
- $error : int|null = null
-
The error constant of the upload (one of PHP's UPLOAD_ERR_XXX constants); null defaults to UPLOAD_ERR_OK
- $test : bool = false
-
Whether the test mode is active Local files are used in test mode hence the code should not enforce HTTP uploads
Tags
Return values
mixed —getClientMimeType()
Returns the file mime type.
public
getClientMimeType() : string
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).
Tags
Return values
string —getClientOriginalExtension()
Returns the original file extension.
public
getClientOriginalExtension() : string
It is extracted from the original file name that was uploaded. This should not be considered as a safe value to use for a file name on your servers.
Return values
string —getClientOriginalName()
Returns the original file name.
public
getClientOriginalName() : string
It is extracted from the request from which the file has been uploaded. This should not be considered as a safe value to use for a file name on your servers.
Return values
string —getContent()
public
getContent() : string
Return values
string —getError()
Returns the upload error.
public
getError() : int
If the upload was successful, the constant UPLOAD_ERR_OK is returned. Otherwise one of the other UPLOAD_ERR_XXX constants is returned.
Return values
int —getErrorMessage()
Returns an informative upload error message.
public
getErrorMessage() : string
Return values
string —getMaxFilesize()
Returns the maximum size of an uploaded file as configured in php.ini.
public
static getMaxFilesize() : int|float
Return values
int|float —The maximum size of an uploaded file in bytes (returns float if size > PHP_INT_MAX)
getMimeType()
Returns the mime type of the file.
public
getMimeType() : string|null
The mime type is guessed using a MimeTypeGuesserInterface instance, which uses finfo_file() then the "file" system binary, depending on which of those are available.
Tags
Return values
string|null —guessClientExtension()
Returns the extension based on the client mime type.
public
guessClientExtension() : string|null
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).
Tags
Return values
string|null —guessExtension()
Returns the extension based on the mime type.
public
guessExtension() : string|null
If the mime type is unknown, returns null.
This method uses the mime type as guessed by getMimeType() to guess the file extension.
Tags
Return values
string|null —isValid()
Returns whether the file has been uploaded with HTTP and no error occurred.
public
isValid() : bool
Return values
bool —move()
Moves the file to a new location.
public
move(string $directory[, string|null $name = null ]) : File
Parameters
- $directory : string
- $name : string|null = null
Tags
Return values
File —getName()
Returns locale independent base name of the given path.
protected
getName(string $name) : string
Parameters
- $name : string
Return values
string —getTargetFile()
protected
getTargetFile(string $directory[, string|null $name = null ]) : self
Parameters
- $directory : string
- $name : string|null = null
Return values
self —parseFilesize()
Returns the given size from an ini value in bytes.
private
static parseFilesize(string $size) : int|float
Parameters
- $size : string
Return values
int|float —Returns float if size > PHP_INT_MAX