FileUpload
final class FileUpload
Provides access to individual files that have been uploaded by a client.
Constants
deprecated IMAGE_MIME_TYPES |
|
Properties
string read-only | $name | ||
string read-only | $sanitizedName | ||
string read-only | $untrustedFullPath | ||
string|null read-only | $contentType | ||
int read-only | $size | ||
string read-only | $temporaryFile | ||
int read-only | $error | ||
bool read-only | $ok | ||
string|null read-only | $contents |
Methods
No description
Returns the original file name as submitted by the browser. Do not trust the value returned by this method.
Returns the sanitized file name. The resulting name contains only ASCII characters [a-zA-Z0-9.-].
Returns the original full path as submitted by the browser during directory upload. Do not trust the value returned by this method. A client could send a malicious directory structure with the intention to corrupt or hack your application.
Detects the MIME content type of the uploaded file based on its signature. Requires PHP extension fileinfo.
Returns the appropriate file extension (without the period) corresponding to the detected MIME type. Requires the PHP extension fileinfo.
Returns the size of the uploaded file in bytes.
Returns the path of the temporary location of the uploaded file.
Returns the path of the temporary location of the uploaded file.
Returns the error code. It is be one of UPLOAD_ERR_XXX constants.
Returns true if the file was uploaded successfully.
Returns true if the user has uploaded a file.
Moves an uploaded file to a new location. If the destination file already exists, it will be overwritten.
Returns true if the uploaded file is an image and the format is supported by PHP, so it can be loaded using the toImage() method.
Converts uploaded image to Nette\Utils\Image object.
Returns a pair of [width, height] with dimensions of the uploaded image.
Returns image file extension based on detected content type (without dot).
Returns the contents of the uploaded file. If the upload was not successful, it returns null.
Details
at line 57
__construct(array|null $value)
No description
at line 77
string
getName()
deprecated
deprecated
No description
at line 87
string
getUntrustedName()
Returns the original file name as submitted by the browser. Do not trust the value returned by this method.
A client could send a malicious filename with the intention to corrupt or hack your application.
at line 98
string
getSanitizedName()
Returns the sanitized file name. The resulting name contains only ASCII characters [a-zA-Z0-9.-].
If the name does not contain such characters, it returns 'unknown'. If the file is JPEG, PNG, GIF, or WebP image, it returns the correct file extension. Do not blindly trust the value returned by this method.
at line 120
string
getUntrustedFullPath()
Returns the original full path as submitted by the browser during directory upload. Do not trust the value returned by this method. A client could send a malicious directory structure with the intention to corrupt or hack your application.
The full path is only available in PHP 8.1 and above. In previous versions, this method returns the file name.
at line 130
string|null
getContentType()
Detects the MIME content type of the uploaded file based on its signature. Requires PHP extension fileinfo.
If the upload was not successful or the detection failed, it returns null.
at line 143
string|null
getSuggestedExtension()
Returns the appropriate file extension (without the period) corresponding to the detected MIME type. Requires the PHP extension fileinfo.
at line 164
int
getSize()
Returns the size of the uploaded file in bytes.
at line 173
string
getTemporaryFile()
Returns the path of the temporary location of the uploaded file.
at line 182
string
__toString()
Returns the path of the temporary location of the uploaded file.
at line 192
int
getError()
Returns the error code. It is be one of UPLOAD_ERR_XXX constants.
at line 201
bool
isOk()
Returns true if the file was uploaded successfully.
at line 210
bool
hasFile()
Returns true if the user has uploaded a file.
at line 220
FileUpload
move(string $dest)
Moves an uploaded file to a new location. If the destination file already exists, it will be overwritten.
at line 242
bool
isImage()
Returns true if the uploaded file is an image and the format is supported by PHP, so it can be loaded using the toImage() method.
Detection is based on its signature, the integrity of the file is not checked. Requires PHP extensions fileinfo & gd.
at line 260
Image
toImage()
Converts uploaded image to Nette\Utils\Image object.
at line 269
array|null
getImageSize()
Returns a pair of [width, height] with dimensions of the uploaded image.
at line 281
string|null
getImageFileExtension()
deprecated
deprecated
Returns image file extension based on detected content type (without dot).
at line 290
string|null
getContents()
Returns the contents of the uploaded file. If the upload was not successful, it returns null.