IUploadedFile

Interface for file uploading class.
Source
IUploadedFile.php
Implementations
UploadedFile

Methods

__construct

IUploadedFile $obj = new IUploadedFile(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 fr 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.

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;}"