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

[eluser]esthonwood[/eluser]
Hi everyone, I need your help. Can anybody help me with multiple file upload? Uploading a single file is ok. I will need to loop through $_FILE and upload it. Any help will be appreciated.

Thanks!
#2

[eluser]xwero[/eluser]
Code:
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size']    = '100';
$config['max_width']  = '1024';
$config['max_height']  = '768';
        
$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();
        }
}
// do something with the errors and/or uploads array
You could even use the $_FILES[$field]['error'] as a first error check
#3

[eluser]esthonwood[/eluser]
Thank you so very much! I really appreciate this! =)
#4

[eluser]blackhalobender[/eluser]
How did you guys solve the error problem? Nobody wants the errors in that big long list of <p>s in the top of the form. People generally want the errors to be next to the problem field.

I tried this:

Code:
$data['photo1'] = '';
        $data['photo2'] = '';
        $data['photo3'] = '';
        $data['photo4'] = '';
        
        $keys = array_keys($_FILES);
        $errors = array();
        $uploads = array();
        foreach($keys as $field){
            
                if ( ! $this->upload->do_upload($field))
                {
                    $data[$field] = $this->upload->display_errors('<p class="errors">','</p>');
                }    
                else
                {
                    $uploads = $this->upload->data();
                }
        }



... but my data array is funky. &lt;?=$field1; ?&gt; works great. But &lt;?=$field4; ?&gt; contains the errors from 1, 2, 3, and 4.

Problemo 2 is that I can't seem to test for the dumb error of: You did not select a file to upload.

I've been on this so long I'm considering hacking the class. I know, bad idea.
#5

[eluser]blackhalobender[/eluser]
Still trying. So $this isn't clearing after each iteration of the loop, thus the loading and reloading of each error.
#6

[eluser]blackhalobender[/eluser]
After reading through the file upload class there is no way do do what I want to do I don't think. The class doesn't load up an array, it just returns the HTML in one big var. The var contains all of the error messages generated by the class with nothing but returns after them. The way it's done you can't even extend the class to only output one error message at a time. It also means you can't trap for certain errors.

Guess I'll have to check for all of the errors myself and load up an array.

Please someone correct me if I'm wrong.




Theme © iAndrew 2016 - Forum software by © MyBB