File
in package
Class File
This class is responsible for handling file storage operations. It provides methods to interact with files, such as reading, writing, and managing file data within the Pickles Framework.
Table of Contents
Properties
- $content : mixed
- $originalName : string
- $type : string
Methods
- __construct() : mixed
- getExtension() : string
- Retrieves the file extension based on the MIME type.
- isImg() : bool
- Determines if the file type represents an image.
- store() : string
- Stores the current file content in the specified directory or the default location.
Properties
$content
private
mixed
$content
$originalName
private
string
$originalName
$type
private
string
$type
Methods
__construct()
public
__construct(mixed $content, string $type, string $originalName) : mixed
Parameters
- $content : mixed
- $type : string
- $originalName : string
getExtension()
Retrieves the file extension based on the MIME type.
public
getExtension() : string
This method splits the MIME type string (e.g., "image/png") into its components using the "/" delimiter and returns the second part, which represents the file extension (e.g., "png").
Return values
string —The file extension derived from the MIME type. If the MIME type is invalid or does not contain a "/", null will be returned.
isImg()
Determines if the file type represents an image.
public
isImg() : bool
This method checks if the file's type starts with the string "image" (case-insensitive), indicating that the file is an image.
Return values
bool —Returns true if the file type starts with "image", otherwise false.
store()
Stores the current file content in the specified directory or the default location.
public
store([string|null $directory = null ]) : string
Parameters
- $directory : string|null = null
-
The directory where the file should be stored. If null, the file will be stored in the default location.
Return values
string —The path where the file was stored.