File
extends SplFileInfo
in package
Wrapper for PHP's built-in SplFileInfo, with goodies.
Tags
Table of Contents
Properties
- $originalMimeType : string|null
- $size : int
- The files size in bytes
Methods
- __construct() : mixed
- Run our SplFileInfo constructor with an optional verification that the path is really a file.
- getDestination() : string
- Returns the destination path for the move operation where overwriting is not expected.
- getMimeType() : string
- Retrieve the media type of the file. SHOULD not use information from the $_FILES array, but should use other methods to more accurately determine the type of file, like finfo, or mime_content_type().
- getRandomName() : string
- Generates a random names based on a simple hash and the time, with the correct file extension attached.
- getSize() : false|int
- Retrieve the file size.
- getSizeByUnit() : false|int|string
- Retrieve the file size by unit.
- guessExtension() : string|null
- Attempts to determine the file extension based on the trusted getType() method. If the mime type is unknown, will return null.
- move() : File
- Moves a file to a new location.
Properties
$originalMimeType
protected
string|null
$originalMimeType
$size
The files size in bytes
protected
int
$size
Methods
__construct()
Run our SplFileInfo constructor with an optional verification that the path is really a file.
public
__construct(string $path[, bool $checkFile = false ]) : mixed
Parameters
- $path : string
- $checkFile : bool = false
Tags
getDestination()
Returns the destination path for the move operation where overwriting is not expected.
public
getDestination(string $destination[, string $delimiter = '_' ][, int $i = 0 ]) : string
First, it checks whether the delimiter is present in the filename, if it is, then it checks whether the last element is an integer as there may be cases that the delimiter may be present in the filename. For the all other cases, it appends an integer starting from zero before the file's extension.
Parameters
- $destination : string
- $delimiter : string = '_'
- $i : int = 0
Return values
stringgetMimeType()
Retrieve the media type of the file. SHOULD not use information from the $_FILES array, but should use other methods to more accurately determine the type of file, like finfo, or mime_content_type().
public
getMimeType() : string
Return values
string —The media type we determined it to be.
getRandomName()
Generates a random names based on a simple hash and the time, with the correct file extension attached.
public
getRandomName() : string
Return values
stringgetSize()
Retrieve the file size.
public
getSize() : false|int
Implementations SHOULD return the value stored in the "size" key of the file in the $_FILES array if available, as PHP calculates this based on the actual size transmitted. A RuntimeException will be thrown if the file does not exist or an error occurs.
Attributes
- #[ReturnTypeWillChange]
Return values
false|int —The file size in bytes, or false on failure
getSizeByUnit()
Retrieve the file size by unit.
public
getSizeByUnit([string $unit = 'b' ]) : false|int|string
Parameters
- $unit : string = 'b'
Return values
false|int|stringguessExtension()
Attempts to determine the file extension based on the trusted getType() method. If the mime type is unknown, will return null.
public
guessExtension() : string|null
Return values
string|nullmove()
Moves a file to a new location.
public
move(string $targetPath[, string|null $name = null ][, bool $overwrite = false ]) : File
Parameters
- $targetPath : string
- $name : string|null = null
- $overwrite : bool = false