Welcome Guest, Not a member yet? Register   Sign In
How do I upload Multiple Files ?

Hi, I want to let users upload 1 image and 1 zip file.

I want to let the image be uploaded to "./uploads/posts" and the zip to "./uploads/files" .. but my below code only allows me to upload 2 images, and not 1 image and 1 zip. When I upload the 2 images, it saves both in ./uploads/posts with both the same name.. except the second file will be the extension twice.. for example..

Below is the controller code:
//getting the username of the logged in user, to later add the username on the file name
        $userdata = $this->user_model->get_online_user_data($this->session->userdata('username'));
        $username = $userdata['username'];

        //Upload PICTURE
        $picture['file_name'] = 'post_'.$username.'_'.now();
        $picture['upload_path'] = './uploads/posts';
        $picture['allowed_types'] = 'png|jpg|gif';
        $picture['max_size'] = '1000000';
        $this->load->library('upload', $picture);
            echo $this->upload->display_errors();
            echo "<h1>Picture Uploaded</h1>";
        //Upload ZIP
        $config['file_name'] = 'file_'.$username.'_'.now();
        $config['upload_path'] = './uploads/files';
        $config['allowed_types'] = 'zip|rar';
        $config['max_size'] = '1000000';
        $this->load->library('upload', $config);
            echo $this->upload->display_errors();
            echo "<h1>ZIP Uploaded</h1>";

You need to call do_upload() twice, once for each file you are uploading. (and obviously make sure that both uploads are valid).

Keep in mind that do_upload() defaults to use the input named 'userfile', so you'll need to pass in the name of the input:

http://ellislab.com/codeigniter/user-gui...ading.html has more detailed information.


I am calling it twice in my above code.

in the block of code for the picture i call it :


and the block of code for the zip i call it:


isnt it where Im putting "picture" or "file" changing it from the default userfile ?

Ah I done it!

basically I have to reinilize the config array and load the library ONLY ONCE!

load the library once above.

and the after the config arrays, inializite the config, with the inilizite function.

See http://ellislab.com/forums/viewthread/156352/

Theme © iAndrew 2016 - Forum software by © MyBB