Uploading multiple images |
[eluser]hema[/eluser]
Hi All, Iam 1 month old in CI. Iam struck with uploading two multiple images at a time.When i submit the form two images should be uploaded. But it is not happening. Can anyone help me out. This is my view file <form method=post action="do_upload" enctype="multipart/form-data"> <table border=1 width=500 height=200> <tr> <td>Image1</td> <td><Input type=file name="userfile"></td> // this file is uploading correctly. if i change userfile to //someother name it will not upoload. I dont no why it happens. </tr> <tr> <td>Image2</td> <td><Input type=file name="Image2"></td> // this file i am unable to upload </tr> </table> </form> this is my controller function do_upload() { $ImageName = ""; $config['upload_path'] = 'application/Pics/'; $config['allowed_types'] = 'gif|jpg|png|jpeg'; //$config['max_size'] = '100'; $config['max_width'] = '1200'; $config['max_height'] = '850'; $this->load->library('upload', $config); if ( ! $this->upload->do_upload()) { $error = array('error' => $this->upload->display_errors()); //$this->load->view('addproduct', $error); } else { $data = array('upload_data' => $this->upload->data()); //$this->load->view('upload_success', $data); foreach($data as $Key => $Value) { $ImageName="$Value[file_name]"; } } }
[eluser]hema[/eluser]
No thanks, I resolved it. Use this function if anyone wants to upload multiple images at a time http://ellislab.com/forums/viewthread/71999/P10/
[eluser]Mikhail Menshinskiy[/eluser]
It happens because you didn't specify a $field in the $this->upload->do_upload() method and CI load file with name 'userfile' by default. Upload class: Code: public function do_upload($field = 'userfile') ie. you should use: Code: $this->upload->do_upload('userfile');
[eluser]toopay[/eluser]
You should validate each file, then upload each file : Code: function do_upload() ps : use code tags when posting your code, it make easier to anyone else when read your code ;-) |
Welcome Guest, Not a member yet? Register Sign In |