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

[eluser]EEssam[/eluser]
Hi,

The following code (http://ellislab.com/forums/viewthread/66017/) is not working for me:

Code:
function upload_images()
    {
        $config['upload_path'] = './system/application/uploads/images/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '2048';
        $config['max_width'] = '0';
        $config['max_height'] = '0';

        $this->load->library('upload', $config);

        $keys = array_keys($_FILES);
        $errors = array();
        $uploads = array();

        foreach ($keys as $field)
        {
            if (!$this->upload->do_upload($field))
            {
                $errors[] = $this->upload->display_errors();
            }
            else
            {
                $uploads = $this->upload->data();
            }
        }
    }

And I have the following in my view:

<?php echo form_upload('myimages[]') ?>
<?php echo form_upload('myimages[]') ?>
<?php echo form_upload('myimages[]') ?>
<?php echo form_upload('myimages[]') ?>

- The error message: You did not select a file to upload.
- I'm using form_open_multipart

Please help, what's wrong?

Thanks.
#2

[eluser]LuckyFella73[/eluser]
Don't you need to set up the arrays when using the form helpers?
like:
Code:
$data_file_1 = array(
   'name' => 'userfile_1',
   'id' => 'userfile_1',
   'size' => '50',
   'style' => 'width:50%',
);
$data_file_2 = array(
   'name' => 'userfile_2',
   'id' => 'userfile_2',
   'size' => '50',
   'style' => 'width:50%',
);
echo form_input($data_file_1);
echo form_input($data_file_2);
and so on ?

As far as i know, the usage of
Code:
myimages[]
Is just a shortcut of
Code:
push_array($destination_array, $new_data)

for example
Code:
$myimages[] = 'data_to_push_into_array_myimages';

But maybe I'm wrong and just are not familiar with the coding style you used!

I don't know how your view file looks in detail so it's hard to say
what could be missing ..
#3

[eluser]crumpet[/eluser]
maybe you get that error because it is trying to uplaod fields you have left blank
from what i can tell your code doesn't account for fields that aren't filled
try putting
die(print_r($keys)); right after you declare that variable and see what you are actaully getting for data




Theme © iAndrew 2016 - Forum software by © MyBB