Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

getUploadedFiles use with multiples inputs

I have multiples inputs os images one theys receiving multiples images and other receive only one, and both are save in diferents directorys.

How can I tell them?

Example of what I using the global variable $ _FILES

$img1 = $_FILES['img1']['tmp_name']

$img2 = $_FILES['img2']['tmp_name']

How i make this using getUploadedFiles???



18.3k

getUploadedFiles(..) returns an array of Phalcon\Http\Request\File objects, so you can use his functions to know everything about them http://docs.phalconphp.com/es/latest/api/Phalcon%5Http%5Request%5File.html



18.3k

getUploadedFiles(..) returns an array of Phalcon\Http\Request\File objects, so you can use his functions to know everything about them http://docs.phalconphp.com/es/latest/api/Phalcon%5Http%5Request%5File.html

edited Feb '15

getUploadedFiles(..) returns an array of Phalcon\Http\Request\File objects, so you can use his functions to know everything about them http://docs.phalconphp.com/es/latest/api/Phalcon%5Http%5Request%5File.html

I know, but i need get the files in differents vars, something like this

//HTML
<input type="file" name="profile" id="profile" />
<input type="file" name="albuns[]" multiple/>

//Controller
$profile_img  = getUploadedFiles('profile');
$albuns_img = getUploadedFiles('albuns');

getUploadedFiles receiving all uploaded files in one array like $_FILES but how differentiate the received inputs? This is my doubt.



18.3k
Accepted
answer

Ahhhhhh know I get it. This has been discussed in other post (http://forum.phalconphp.com/discussion/4418/how-to-get-an-uploaded-file-directly).

edited Feb '15

Ahhhhhh know I get it. This has been discussed in other post (http://forum.phalconphp.com/discussion/4418/how-to-get-an-uploaded-file-directly).

Unfortunately does not allow Phalcon What do I want to do as you showed, I could do otherwise, but the possibility of receiving the data according to your name or id should be implemented in future versions of the framework for it makes us lose a lot of time with something that should be simple.



1.4k
edited Feb '15

i believe u can extend http request class for that. something along the line of.

of course this is zep, so yeah 2.0 =d

/**
     * Gets attached files as Phalcon\Http\Request\File instances
     *
     * @param boolean notErrored
     * @return Phalcon\Http\Request\File[]
     */
    public function getUploadFiles(string index, boolean notErrored = false) -> <File[]> | null
    {
        var superFiles, prefix, input, smoothInput, files, file, dataFile;
        if fetch superFiles, _FILES[index] {

        let files = [];

        if (count(superFiles) > 0) {

            for prefix, input in superFiles {
                if (typeof input["name"] == "array") {
                    let smoothInput = this->smoothFiles(input["name"], input["type"], input["tmp_name"], input["size"], input["error"], prefix);

                    for file in smoothInput {
                        if (notErrored == false || file["error"] == UPLOAD_ERR_OK) {
                            let dataFile = [
                                "name": file["name"],
                                "type": file["type"],
                                "tmp_name": file["tmp_name"],
                                "size": file["size"],
                                "error": file["error"]
                            ];

                            let files[] = new File(dataFile, file["key"]);
                        }
                    }
                } else {
                    if (notErrored == false || input["error"] == UPLOAD_ERR_OK) {
                        let files[] = new File(input, prefix);
                    }
                }
            }
        }

        return files;
        }
        return null;
    }

i believe u can extend http request class for that. something along the line of.

of course this is zep, so yeah 2.0 =d

```zep /** * Gets attached files as Phalcon\Http\Request\File instances * * @param boolean notErrored * @return Phalcon\Http\Request\File[] */ public function getUploadFiles(string index, boolean notErrored = false) -> <File[]> | null { var superFiles, prefix, input, smoothInput, files, file, dataFile; if fetch superFiles, _FILES[index] {

   let files = [];

 if (count(superFiles) > 0) {

     for prefix, input in superFiles {
         if (typeof input["name"] == "array") {
             let smoothInput = this->smoothFiles(input["name"], input["type"], input["tmp_name"], input["size"], input["error"], prefix);

             for file in smoothInput {
                 if (notErrored == false || file["error"] == UPLOAD_ERR_OK) {
                     let dataFile = [
                         "name": file["name"],
                         "type": file["type"],
                         "tmp_name": file["tmp_name"],
                         "size": file["size"],
                         "error": file["error"]
                     ];

                     let files[] = new File(dataFile, file["key"]);
                 }
             }
         } else {
             if (notErrored == false || input["error"] == UPLOAD_ERR_OK) {
                 let files[] = new File(input, prefix);
             }
         }
     }
 }

 return files;
 }
 return null;

}

```

where be located this class?



1.4k

anywhere, convert the zep to php and u can use it in a library folder