Class File
Representation of a POST file.
-
ICanBoogie\HTTP\File
implements
ICanBoogie\ToArray,
ICanBoogie\HTTP\FileOptions
uses
ICanBoogie\Accessor\AccessorTrait (not available)
Methods summary
public static
from( array|string $properties_or_name
)
: ICanBoogie\HTTP\File
Creates a ICanBoogie\HTTP\File
instance.
Parameters
$properties_or_name
- An array of properties or a file identifier.
Returns
protected
get_name( void )
: string
Returns the name of the file.
Returns the name of the file.
Returns
string
protected
get_unsuffixed_name( void )
: string
Returns the name of the file, without its extension.
Returns the name of the file, without its extension.
Returns
string
protected
get_type( void )
: string|null
Returns the type of the file.
Returns the type of the file.
If the ICanBoogie\HTTP\File::$type
property was not defined during construct, the type
is guessed from the name or the pathname of the file.
Returns
string|null
The MIME type of the file, or null
if it cannot be determined.
protected
get_size( void )
: integer|false
Returns the size of the file.
Returns the size of the file.
If the ICanBoogie\HTTP\File::$size
property was not defined during construct, the size
is guessed using the pathname of the file. If the pathname is not available the method
returns null
.
Returns
integer|false
The size of the file or false
if it cannot be determined.
protected
get_is_valid( void )
: boolean
Whether the file is valid.
Whether the file is valid.
A file is considered valid if it has no error code, if it has a size,
if it has either a temporary name or a pathname and that the file actually exists.
Returns
boolean
true
if the file is valid, false
otherwise.
protected
get_pathname( void )
: string
Returns the pathname of the file.
protected
__construct( array $properties
)
public
to_array( void )
: array
Returns an array representation of the instance.
Returns an array representation of the instance.
The following properties are exported:
Returns
array
protected
get_error( void )
: string
Returns the error code.
Returns
string
protected
get_error_message( void )
: ICanBoogie\I18n\FormattedString|ICanBoogie\FormattedString|string|null
Returns the message associated with the error.
Returns the message associated with the error.
Returns
ICanBoogie\I18n\FormattedString|ICanBoogie\FormattedString|string|null
protected
get_extension( void )
: string|null
Returns the extension of the file, if any.
Returns the extension of the file, if any.
Note: The extension includes the dot e.g. ".zip". The extension is always in lower case.
Returns
string|null
protected
get_is_uploaded( void )
: boolean
Checks if a file is uploaded.
Checks if a file is uploaded.
Returns
boolean
true
if the file is uploaded, false
otherwise.
public
match( string|array $type
)
: boolean
Checks if the file matches a MIME class, a MIME type, or a file extension.
Checks if the file matches a MIME class, a MIME type, or a file extension.
Parameters
$type
The type can be a MIME class (e.g. "image"),
a MIME type (e.g. "image/png"), or an extensions (e.g. ".zip"). An array can be used to
check if a file matches multiple type e.g. [ "image", ".mp3" ]
, which matches any type
of image or files with the ".mp3" extension.
Returns
boolean
true
if the file matches (or $type
is empty), false
otherwise.
public
move( string $destination
, boolean $overwrite
= self::MOVE_NO_OVERWRITE )
Moves the file.
Parameters
Throws
Exception
if the file failed to be moved.
Constants summary
MOVE_OVERWRITE
: boolean
true
MOVE_NO_OVERWRITE
: boolean
false
OPTION_ERROR
,
OPTION_NAME
,
OPTION_PATHNAME
,
OPTION_SIZE
,
OPTION_TMP_NAME
,
OPTION_TYPE
Properties summary
Magic properties
public read-only
$name
: string
public read-only
$type
: string
public read-only
$size
: string
public read-only
$error
: string
Error code, one of UPLOAD_ERR_*
.
public read-only
$error_message
: string
A formatted message representing the error.
public read-only
$pathname
: string
public read-only
$extension
: string
The extension of the file. If any, the dot is included e.g. ".zip".
public read-only
$unsuffixed_name
: string
The name of the file without its extension.
public read-only
$is_uploaded
: boolean
true
if the file is uploaded, false
otherwise.
public read-only
$is_valid
: boolean
true
if the file is valid, false
otherwise. See: is_valid().