Image
extends File
in package
Encapsulation of an Image file
Table of Contents
- $imageType : int
- The image type constant.
- $mime : string
- The image's mime type, i.e. image/jpeg
- $origHeight : int|float
- The original image height in pixels.
- $origWidth : int|float
- The original image width in pixels.
- $sizeStr : string
- attributes string with size info: 'height="100" width="200"'
- $originalMimeType : null|string
- Original MimeType
- $size : int
- The files size in bytes
- __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() : int
- Retrieve the file size.
- getSizeByUnit() : 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
int|float
$origHeight
$origWidth
The original image width in pixels.
public
int|float
$origWidth
$sizeStr
attributes string with size info: 'height="100" width="200"'
public
string
$sizeStr
$originalMimeType
Original MimeType
protected
null|string
$originalMimeType
= null
$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
Return values
mixed —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
bool —getDestination()
Returns the destination path for the move operation where overwriting is not expected.
public
getDestination(string $destination[, string $delimiter = '_' ], int $i) : 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
Return values
string —getMimeType()
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>|bool —getRandomName()
Generates a random names based on a simple hash and the time, with the correct file extension attached.
public
getRandomName() : string
Return values
string —getSize()
Retrieve the file size.
public
getSize() : 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.
Return values
int —The file size in bytes
getSizeByUnit()
Retrieve the file size by unit.
public
getSizeByUnit([string $unit = 'b' ]) : int|string
Parameters
- $unit : string = 'b'
Return values
int|string —guessExtension()
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|null —move()
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