UploadedFile

When managing uploads via an "IUpload" instance, each uploaded file and it's actions will be wrapped inside an instance of "IUploadedFile".
You can access the "IUploadedFile" object(s) or iterate over them via the "IUpload" instance. The "IUpload" instance itself is accessed and created via the "IRequest" instance. e.g: "$uploadedFile = $request->Upload->get('upload-key');" or "foreach ($request->Upload as $uploadKey => $uploadedFileObj)". As instanced of this class are created and accessed via an "IRequest", this class is not included into the autoload.
Source
UploadedFile.php
Implements
IUploadedFile
Depends on
UploadError

Properties

error

$obj->error

Read-only property! Uploaded file upload error.

name

$obj->name

Read-only property! Uploaded file original filename.

size

$obj->size

Read-only property! Uploaded file size.

temp

$obj->temp

Read-only property! Uploaded file temp path.

type

$obj->type

Read-only property! Uploaded file mime type.

Methods

__construct

UploadedFile $obj = new UploadedFile(array uploadInfo)

Creates an UploadedFile instance.

Arguments

    uploadInfo (array)
    Upload info for the file from "$_FILES"

Returns

void

moveTo

void $obj->moveTo(string path)

Moves the uploaded temp file to where it should go.

Arguments

    path (string)
    File destination path.

Returns

void

Throws

validate

bool|array $obj->validate(array rules)

Validate the uploaded file. This method is very helpful when you have to prepare things before moving the uploaded file for example if you want to create a new record in the database and you want the PK to create the file-name, this method can ensure you that everything is OK. Note this method will not throw exception, the throw exceptions mentioned below are thrown if method moveTo is called instead.

Arguments

    rules (array)
    Validating rules
    {
        bool          required : true
            if file has not been uploaded an "UploadError" will
            be thrown,
        int|string    size     :
            int=number of bytes string=number+unit e.g. "12M", "100B", "2K"
            if the uploaded file-size is greater than this number then  an
            "UploadError" will be thrown,
        string|array  type     :
            if the mime-type of the uploaded file is not equal to this
            value(if string) or not exists in the list(if array) then an
            "UploadError" will be thrown,
        string|array  ext      :
            if the file-name extension of the uploaded file is not equal to
            this value(if string) or not exists in the list(if array) then an
            "UploadError" will be thrown,
        array|string  plugin   :
            function or method to validate the upload - the UploadFile instance
            is passed to the function/method and if the function/method returns
            false then an "UploadError" will be thrown.
            The function/method can be as
            "functionName"
            "ClassName::methodName"
            ["ClassName", "methodName"]
            [object, "methodName"]
        string        check   :
            alias for "plugin",
    }
    

Returns

bool|array
true=upload is validated, array=errors {error-code:msg,}, use "===" for checking this value e.g. "if (($errors=$file->validate(rules)) === true) {ok;} else {bad;}"