Image
extends File
in package
Encapsulation of an Image file
Tags
Table of Contents
Properties
- $imageType : int
- The image type constant.
- $mime : string
- The image's mime type, i.e. image/jpeg
- $origHeight : float|int
- The original image height in pixels.
- $origWidth : float|int
- The original image width in pixels.
- $sizeStr : string
- attributes string with size info: 'height="100" width="200"'
- $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.
- copy() : bool
- Makes a copy of itself to the new location. If no filename is provided it will use the existing filename.
- 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().
- getProperties() : array<string|int, mixed>|bool
- Get image properties
- 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
$imageType
The image type constant.
public
int
$imageType
Tags
$mime
The image's mime type, i.e. image/jpeg
public
string
$mime
$origHeight
The original image height in pixels.
public
float|int
$origHeight
$origWidth
The original image width in pixels.
public
float|int
$origWidth
$sizeStr
attributes string with size info: 'height="100" width="200"'
public
string
$sizeStr
$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
copy()
Makes a copy of itself to the new location. If no filename is provided it will use the existing filename.
public
copy(string $targetPath[, string|null $targetName = null ][, int $perms = 0644 ]) : bool
Parameters
- $targetPath : string
-
The directory to store the file in
- $targetName : string|null = null
-
The new name of the copied file.
- $perms : int = 0644
-
File permissions to be applied after copy.
Return values
boolgetDestination()
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.
getProperties()
Get image properties
public
getProperties([bool $return = false ]) : array<string|int, mixed>|bool
A helper function that gets info about the file
Parameters
- $return : bool = false
Return values
array<string|int, mixed>|boolgetRandomName()
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