UploadedFile
extends UploadedFile
in package
Uses
FileHelpers, Macroable
A file uploaded through a form.
Table of Contents
- $hashName : string
- The cache copy of the file's hash name.
- $macros : array<string|int, mixed>
- The registered string macros.
- $error : mixed
- $mimeType : mixed
- $originalName : mixed
- $size : mixed
- $test : mixed
- __call() : mixed
- Dynamically handle calls to the class.
- __callStatic() : mixed
- Dynamically handle calls to the class.
- __construct() : mixed
- Constructs a new file from the given path.
- clientExtension() : string
- Get the file's extension supplied by the client.
- createFromBase() : static
- Create a new file instance from a base instance.
- extension() : string
- Get the file's extension.
- fake() : FileFactory
- Begin creating a new file fake.
- getClientMimeType() : string
- Returns the file mime type.
- getClientOriginalExtension() : string
- Returns the original file extension.
- getClientOriginalName() : string
- 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.
- hashName() : string
- Get a filename for the file.
- hasMacro() : bool
- Checks if macro is registered.
- isValid() : bool
- Returns whether the file was uploaded successfully.
- macro() : void
- Register a custom macro.
- mixin() : void
- Mix another object into the class.
- move() : self
- Moves the file to a new location.
- path() : string
- Get the fully qualified path to the file.
- store() : string|false
- Store the uploaded file on a filesystem disk.
- storeAs() : string|false
- Store the uploaded file on a filesystem disk.
- storePublicly() : string|false
- Store the uploaded file on a filesystem disk with public visibility.
- storePubliclyAs() : string|false
- Store the uploaded file on a filesystem disk with public visibility.
- getName() : string
- Returns locale independent base name of the given path.
- getTargetFile() : mixed
- parseOptions() : array<string|int, mixed>
- Parse and format the given options.
- parseFilesize() : int
- Returns the given size from an ini value in bytes.
Properties
$hashName
The cache copy of the file's hash name.
protected
string
$hashName
= null
$macros
The registered string macros.
protected
static array<string|int, mixed>
$macros
= []
$error
private
mixed
$error
$mimeType
private
mixed
$mimeType
$originalName
private
mixed
$originalName
$size
private
mixed
$size
$test
private
mixed
$test
Methods
__call()
Dynamically handle calls to the class.
public
__call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —__callStatic()
Dynamically handle calls to the class.
public
static __callStatic(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —__construct()
Constructs a new file from the given path.
public
__construct(string $path[, bool $checkPath = true ]) : mixed
Parameters
- $path : string
-
The path to the file
- $checkPath : bool = true
-
Whether to check the path or not
Tags
Return values
mixed —clientExtension()
Get the file's extension supplied by the client.
public
clientExtension() : string
Return values
string —createFromBase()
Create a new file instance from a base instance.
public
static createFromBase(UploadedFile $file[, bool $test = false ]) : static
Parameters
- $file : UploadedFile
- $test : bool = false
Return values
static —extension()
Get the file's extension.
public
extension() : string
Return values
string —fake()
Begin creating a new file fake.
public
static fake() : FileFactory
Return values
FileFactory —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 —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
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 —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.
Return values
int|null —The file size
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 MimeTypeGuesser instance, which uses finfo(), mime_content_type() and the system binary "file" (in this order), 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
hashName()
Get a filename for the file.
public
hashName([string $path = null ]) : string
Parameters
- $path : string = null
Return values
string —hasMacro()
Checks if macro is registered.
public
static hasMacro(string $name) : bool
Parameters
- $name : string
Return values
bool —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
macro()
Register a custom macro.
public
static macro(string $name, object|callable $macro) : void
Parameters
- $name : string
- $macro : object|callable
Return values
void —mixin()
Mix another object into the class.
public
static mixin(object $mixin) : void
Parameters
- $mixin : object
Return values
void —move()
Moves the file to a new location.
public
move(string $directory[, string $name = null ]) : self
Parameters
- $directory : string
-
The destination folder
- $name : string = null
-
The new file name
Tags
Return values
self —A File object representing the new file
path()
Get the fully qualified path to the file.
public
path() : string
Return values
string —store()
Store the uploaded file on a filesystem disk.
public
store(string $path[, array<string|int, mixed>|string $options = [] ]) : string|false
Parameters
- $path : string
- $options : array<string|int, mixed>|string = []
Return values
string|false —storeAs()
Store the uploaded file on a filesystem disk.
public
storeAs(string $path, string $name[, array<string|int, mixed>|string $options = [] ]) : string|false
Parameters
- $path : string
- $name : string
- $options : array<string|int, mixed>|string = []
Return values
string|false —storePublicly()
Store the uploaded file on a filesystem disk with public visibility.
public
storePublicly(string $path[, array<string|int, mixed>|string $options = [] ]) : string|false
Parameters
- $path : string
- $options : array<string|int, mixed>|string = []
Return values
string|false —storePubliclyAs()
Store the uploaded file on a filesystem disk with public visibility.
public
storePubliclyAs(string $path, string $name[, array<string|int, mixed>|string $options = [] ]) : string|false
Parameters
- $path : string
- $name : string
- $options : array<string|int, mixed>|string = []
Return values
string|false —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 —containing
getTargetFile()
protected
getTargetFile(mixed $directory[, mixed $name = null ]) : mixed
Parameters
- $directory : mixed
- $name : mixed = null
Return values
mixed —parseOptions()
Parse and format the given options.
protected
parseOptions(array<string|int, mixed>|string $options) : array<string|int, mixed>
Parameters
- $options : array<string|int, mixed>|string
Return values
array<string|int, mixed> —parseFilesize()
Returns the given size from an ini value in bytes.
private
static parseFilesize(mixed $size) : int
Parameters
- $size : mixed
Return values
int —The given size in bytes