File Upload
The File object represents a file ready to be uploaded to the server. With this class, you can customize files before sending them to the Uploader or Storage class for final upload. Optionally, you can change the filename or set a symlink path to generate a symbolic link for files stored in the private storage directory.
- Class namespace:
\Luminova\Http\File
Methods
constructor
Constructs a File object.
public __construct(int $index, string|null $name = null, string|null $type = null, int $size, string|null $mime = null, string|null $extension = null, string|null $temp = null, int $error): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$index | int | The index of the file. |
$name | string|null | The name of the file. |
$type | string|null | The MIME type of the file. |
$size | int | The size of the file in bytes. |
$mime | string|null | The MIME type of the file. |
$extension | string|null | The file extension. |
$temp | string|null | The temporary file path. |
$error | int | The error code of the file upload. |
getters
Magic getter method to allow access to protected properties.
<?php
echo $file->name;
echo $file->type;
echo $file->size;
echo $file->mime;
echo $file->extension;
echo $file->temp;
echo $file->error;
echo $file->message;
echo $file->index;getIndex
Gets the index of the file.
public getIndex(): intReturn Value:
int - The index of the file.
getName
Gets the name of the file.
public getName(): string|nullReturn Value:
string|null - The name of the file.
getType
Gets the MIME type of the file.
public getType(): string|nullReturn Value:
string|null - The MIME type of the file.
getSize
Gets the size of the file in bytes.
public getSize(): intReturn Value:
int - The size of the file in bytes.
getMime
Gets the MIME type of the file.
public getMime(): string|nullReturn Value:
string|null - The MIME type of the file.
getExtension
Gets the file extension.
public getExtension(): string|nullReturn Value:
string|null - The file extension.
getTemp
Gets the temporary file path.
public getTemp(): string|nullReturn Value:
string|null - The temporary file path.
getError
Gets the error code of the file upload.
public getError(): intReturn Value:
int - The error code of the file upload.
getMessage
Gets the validation error message.
public getMessage(): string|nullReturn Value:
string|null - Return the validation error message.
getConfig
Gets file upload configurations.
public getConfig(): \stdClass|nullReturn Value:
\stdClass|null - Return upload configurations.
setName
This method allows you to change the file name before finally uploading.
public setName(string $name): selfParameters:
| Parameter | Type | Description |
|---|---|---|
$name | string | The name of the file. |
Return Value:
self - Return instance of self.
Throws:
- \Luminova\Exceptions\StorageException - If the filename contains paths or does not have a valid file extension type.
setConfig
To set file configurations before uploading.
public setConfig(array<string,mixed> $config): selfParameters:
| Parameter | Type | Description |
|---|---|---|
$config | array<string,mixed> | Configuration data for the upload. |
Return Value:
self - Return instance of self.
The configurations will be used in validating file before uploading to server.
Options
upload_path(string) The path where files will be uploaded.max_size(int) Maximum allowed file size in bytes.min_size(int) Minimum allowed file size in bytes.allowed_types(string) Allowed file types separated by '|'.chunk_length(int) Length of chunk in bytes (default: 5242880).if_existed(string) How to handle existing files [overwrite or retain] (default: overwrite).symlink(string) Specify a valid path to create a symlink after upload was completed (e.g /public/assets/).
free
Reset file configuration and remove temp file.
public free(): voidvalid
Checks if the file is valid according to the specified configuration.
public valid(): boolReturn Value:
bool - True if the file is valid, false otherwise.