Welcome Guest, Not a member yet? Register   Sign In
Multiple File Upload
#1

[eluser]usefulidiot[/eluser]
As the codeigniter upload library only allows you to upload one file at a time, I had a look around google to see how other people had implemented multiple file upload.

Alot of examples would have
userfile_1
userfile_2
userfile_3 etc

and then check if these additional fields were set and process them.


Correct me if I'm wrong but does this not seem the obvious solution?

<input type="file" name="photo[]" size="20" />

Have the input filename as an array so we can have as many as we like.

Code:
$upload_files = $_FILES;

for($i = 0; $i < count($upload_files['photo']['name']); $i++) {
    $_FILES['photo'] = array(
        'name' => $upload_files['photo']['name'][$i],
        'type' => $upload_files['photo']['type'][$i],
        'tmp_name' => $upload_files['photo']['tmp_name'][$i],
        'error' => $upload_files['photo']['error'][$i],
        'size' => $upload_files['photo']['size'][$i]
    );

    $this->_upload();
}

And just manually assign the current file to $_FILES.




Theme © iAndrew 2016 - Forum software by © MyBB