ICanBoogie
  • Documentation
  • API Reference
  • HTTP master
Namespaces
  • ICanBoogie
    • Exception
    • HTTP
      • Headers
      • Request
      • RequestDispatcher
Classes
  • CallableDispatcher
  • DispatcherProvider
  • File
  • FileInfo
  • FileList
  • FileResponse
  • Headers
  • ProvideDispatcher
  • RedirectResponse
  • Request
  • RequestDispatcher
  • RequestOptionsMapper
  • RequestRange
  • Response
  • Status
  • WeightedDispatcher
Interfaces
  • Dispatcher
  • Exception
  • FileOptions
  • RequestMethods
  • RequestOptions
  • ResponseStatus
  • SecurityError
Exceptions
  • AuthenticationRequired
  • ClientError
  • DispatcherNotDefined
  • DispatcherProviderNotDefined
  • ForceRedirect
  • MethodNotSupported
  • NotFound
  • PermissionRequired
  • ServerError
  • ServiceUnavailable
  • StatusCodeNotValid

Class File

Representation of a POST file.

ICanBoogie\HTTP\File implements ICanBoogie\ToArray, ICanBoogie\HTTP\FileOptions uses ICanBoogie\Accessor\AccessorTrait (not available)
Namespace: ICanBoogie\HTTP
Located at File.php

Methods summary

public static from( array|string $properties_or_name ) : ICanBoogie\HTTP\File

Creates a ICanBoogie\HTTP\File instance.

Creates a ICanBoogie\HTTP\File instance.

Parameters

$properties_or_name
An array of properties or a file identifier.

Returns

ICanBoogie\HTTP\File
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.

Returns the pathname of the file.

Note: If the ICanBoogie\HTTP\File::$pathname property is empty, the ICanBoogie\HTTP\File::$tmp_name property is returned.

Returns

string
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:

  • ICanBoogie\HTTP\File::$name
  • $unsuffixed_name
  • $extension
  • ICanBoogie\HTTP\File::$type
  • ICanBoogie\HTTP\File::$size
  • ICanBoogie\HTTP\File::$pathname
  • ICanBoogie\HTTP\File::$error
  • $error_message

Returns

array
protected get_error( void ) : string

Returns the error code.

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.

Moves the file.

Parameters

$destination
Pathname to the destination file.
$overwrite

Use ICanBoogie\HTTP\File::MOVE_OVERWRITE to delete the destination before the file is moved. Defaults to ICanBoogie\HTTP\File::MOVE_NO_OVERWRITE.

Throws

Exception
if the file failed to be moved.

Constants summary

MOVE_OVERWRITE : boolean
true
MOVE_NO_OVERWRITE : boolean
false

Constants inherited from ICanBoogie\HTTP\FileOptions

OPTION_ERROR, OPTION_NAME, OPTION_PATHNAME, OPTION_SIZE, OPTION_TMP_NAME, OPTION_TYPE

Properties summary

protected $name : string

Name of the file.

Name of the file.


		
protected $type

		
protected $size

		
protected $tmp_name

		
protected $error

		
protected $pathname

		

Magic properties

public read-only $name : string

Name of the file.

public read-only $type : string

MIME type of the file.

public read-only $size : string

Size of the file.

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

Pathname of the file.

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().

HTTP master – Check on GitHub – API documentation generated by ApiGen