Uploads
class Uploads
Provides support for file uploads.
Constants
| MULTIPLE |
Constant for specifying multiple file upload. |
| SINGLE |
Constant for specifying single file upload. |
Properties
| private string | $_bucket | Path to the bucket where file are stored. |
|
| protected array | $_allowedFileTypes | An array of allowed file types. |
|
| private array | $_errors | An array of error objects. |
|
| protected string | $_fieldName | The name of the field associated with file upload. |
|
| protected array | $_files | An array containing objects with information about files. |
|
| protected int | $_maxAllowedSize | The maximum allowed upload size. |
|
| protected string | $sizeMsg | Message describing maximum allowable size. |
Methods
Creates instance of Uploads class.
Adds an error message to the $_errors array.
Processes list of errors associated with uploads and makes them presentable to user during validation.
Generates a unique filename for an uploaded file while preserving its extension.
Getter function for the $_files array.
Handles file uploads and returns an Uploads instance if valid.
Restructures $_FILES data based on mode.
Performs validation tasks.
Performs file upload.
Reports on success of validation.
Validates file type and sets error message if file type is invalid.
Validates file size and sets error message if file is too large.
Details
at line 72
__construct(array|string $files, array $fileTypes, int $maxAllowedSize, string $bucket, string $sizeMsg, string $mode)
Creates instance of Uploads class.
at line 98
protected void
addErrorMessage(string $name, string $message)
Adds an error message to the $_errors array.
at line 115
void
errorReporting(bool|array $errors, Model $model, string $name)
Processes list of errors associated with uploads and makes them presentable to user during validation.
at line 140
string
generateUploadFilename(string $originalFilename)
Generates a unique filename for an uploaded file while preserving its extension.
Uses a cryptographically secure random hash to create a unique base name. Falls back to 'bin' if no extension is found in the original filename.
at line 153
array
getFiles()
Getter function for the $_files array.
at line 172
static Uploads|null
handleUpload(array $file, string $uploadModel, string $bucket, string $sizeMsg, Model $model, string $name, string $mode = self::SINGLE)
Handles file uploads and returns an Uploads instance if valid.
at line 218
static array
restructureFiles(array $files, string $mode = self::SINGLE)
Restructures $_FILES data based on mode.
at line 250
void
runValidation()
Performs validation tasks.
at line 286
void
upload(string $path, string $uploadName, string $fileName)
Performs file upload.
at line 306
bool|array
validates()
Reports on success of validation.
at line 315
protected void
validateFileType()
Validates file type and sets error message if file type is invalid.
at line 355
protected void
validateSize()
Validates file size and sets error message if file is too large.