Welcome Guest, Not a member yet? Register   Sign In
Multiple file upload problem
#1

[eluser]dallen33[/eluser]
I found this handy script on StackExchange that allows for multiple uploads. Except it doesn't work, for me, at least. In the HTML, I have a simple upload form that you can add more upload forms to. So you hit "Add upload" and another input is built. Simple stuff.

Here are the problems:
1. If I choose 1 file to upload, I get the following errors: Message: is_uploaded_file() expects parameter 1 to be string, array given and Message: Undefined offset: 1 repeated 5 times (in reference to the code below), and then shows Message: is_uploaded_file() expects parameter 1 to be string, array given again.
2. If I choose 2 files, I get Message: is_uploaded_file() expects parameter 1 to be string, array given twice.

The error array is always returned as You did not select a file to upload..

What am I doing wrong? Any ideas?

Here's my controller:
Code:
$dir = random_string('alnum', 10);
mkdir('/Applications/MAMP/htdocs/extras/uploads/temp/'.$dir);

$this->load->library('upload');
$error = 0;

for ($i = 0; $i < count($_FILES['userfile']['name']); $i++):
    $_FILES['userfile']['name']                = $_FILES['userfile']['name'][$i];
    $_FILES['userfile']['type']                = $_FILES['userfile']['type'][$i];
    $_FILES['userfile']['tmp_name']        = $_FILES['userfile']['tmp_name'][$i];
    $_FILES['userfile']['error']            = $_FILES['userfile']['error'][$i];
    $_FILES['userfile']['size']                = $_FILES['userfile']['size'][$i];
    
    $config['upload_path']                         = '/Applications/MAMP/htdocs/extras/uploads/temp/'.$dir;
    $config['allowed_types']                    = 'jpg|jpeg|gif|png';
    
    $this->upload->initialize($config);

    if ($this->upload->do_upload('userfile')):
        $error += 0;
    else:
        $error += 1;
    endif;
endfor;

if ($error > 0):
    $error = array('error' => $this->upload->display_errors());
    print_r($error);
else:
    $data = array('upload_data' => $this->upload->data());
    print_r($data);
endif;

And my &lt;input&gt;'s look like this:
Code:
&lt;input id="userfile1" name="userfile[]" type="file" /&gt;


Messages In This Thread
Multiple file upload problem - by El Forum - 05-17-2011, 04:10 PM
Multiple file upload problem - by El Forum - 05-17-2011, 04:23 PM
Multiple file upload problem - by El Forum - 05-17-2011, 04:25 PM
Multiple file upload problem - by El Forum - 05-17-2011, 05:01 PM
Multiple file upload problem - by El Forum - 05-18-2011, 07:09 AM
Multiple file upload problem - by El Forum - 05-18-2011, 12:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB