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|null
- Returns the file mime type.
- getClientOriginalExtension() : string
- Returns the original file extension.
- getClientOriginalName() : string|null
- Returns the original file name.
- getClientSize() : int|null
- Returns the file size.
- getError() : int
- Returns the upload error.
- getErrorMessage() : string
- Returns an informative upload error message.
- getMaxFilesize() : int
- 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 was uploaded successfully.
- move() : File
- Moves the file to a new location.
- getName() : string
- Returns locale independent base name of the given path.
- getTargetFile() : self
- parseFilesize() : int
- 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
= false
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|null
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|null —The mime type
getClientOriginalExtension()
Returns the original file extension.
public
getClientOriginalExtension() : string
It is extracted from the original file name that was uploaded. Then it should not be considered as a safe value.
Return values
string —The extension
getClientOriginalName()
Returns the original file name.
public
getClientOriginalName() : string|null
It is extracted from the request from which the file has been uploaded. Then it should not be considered as a safe value.
Return values
string|null —The original name
getClientSize()
Returns the file size.
public
getClientSize() : int|null
It is extracted from the request from which the file has been uploaded. Then it should not be considered as a safe value.
Tags
Return values
int|null —The file sizes
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 —The upload error
getErrorMessage()
Returns an informative upload error message.
public
getErrorMessage() : string
Return values
string —The error message regarding the specified error code
getMaxFilesize()
Returns the maximum size of an uploaded file as configured in php.ini.
public
static getMaxFilesize() : int
Return values
int —The maximum size of an uploaded file in bytes
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 —The guessed mime type (e.g. "application/pdf")
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 —The guessed extension or null if it cannot be guessed
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 —The guessed extension or null if it cannot be guessed
isValid()
Returns whether the file was uploaded successfully.
public
isValid() : bool
Return values
bool —True if the file has been uploaded with HTTP and no error occurred
move()
Moves the file to a new location.
public
move(string $directory[, string $name = null ]) : File
Parameters
- $directory : string
-
The destination folder
- $name : string = null
-
The new file name
Tags
Return values
File —A File object representing the new file
getName()
Returns locale independent base name of the given path.
protected
getName(string $name) : string
Parameters
- $name : string
-
The new file name
Return values
string —getTargetFile()
protected
getTargetFile(mixed $directory[, mixed $name = null ]) : self
Parameters
- $directory : mixed
- $name : mixed = null
Return values
self —parseFilesize()
Returns the given size from an ini value in bytes.
private
static parseFilesize(mixed $size) : int
Parameters
- $size : mixed