ShoeLace1291 Posted July 27, 2011 Share Posted July 27, 2011 I have a form where a user can upload photos to their gallery. I want them to be able to upload more than one photo at a time. So in my upload form, I have a file input called "files[]" along with a javascript code that let's them add more file fields with the same name. The PHP script that I have made goes through several steps. First, it goes through the process of the actual file upload. If the file upload is a success, it then creates an attachment file(as a database record) and then it creates the photo record in the database. When I return the upload data array, none of the array keys have any values. The display_errors function doesn't return any errors, either. Any ideas? $this->load->library('form_validation'); $this->form_validation->set_rules('files', 'Choose File', 'required'); if($this->form_validation->run() == FALSE){ $data = array( 'ALBUM_TITLE' => $album['ALBUM_TITLE'], 'FORM_OPEN' => form_open('gallery/photos/upload/'.$this->uri->segment(4)), 'VALIDATION_ERRORS' => validation_errors() ); $this->parser->parse('gallery/photo_upload.tpl', $data); } else { $limit = count($this->input->post('files')); $photo_ids = ''; for($i=0;$i<=$limit;$i++){ $config = array( //Preferences to validate the image before uploading it 'upload_path' => './attachments', 'allowed_types' => 'jpg|gif|bmp', 'max_size' => '100', 'max_width' => '950', 'max_height' => '631', 'overwrite' => FALSE, 'encrypt_name' => TRUE, 'remove_spaces' => TRUE ); $this->load->library('upload', $config); if($this->upload->do_upload('files['.$i.']')){ $file = $this->upload->data(); $info = array( //Information to pass to the attachment class for creation 'author_id' => $member['id'], 'file_name' => $file['file_name'], 'file_size' => $file['file_size'], 'file_width' => $file['file_width'], 'file_height' => $file['file_height'] ); if($this->attachment->create($info)){ $info = array( //Information to pass to the photo class for creation(upload data) 'author_id' => $member['id'], 'date_posted' => now(), 'attachment_id' => $this->attachment->insert_id ); if($this->photo->create($info)){ $photo_ids[] = $this->photo->insert_id; $photo_errors = 0; } else { $photo_errors = $photo_errors + 1; } } else { $attachment_errors = $attachment_errors + 1; } } else { $this->upload->display_errors('<p>', '</p>'); } } } Quote Link to comment https://forums.phpfreaks.com/topic/242904-codeigniter-multiple-file-upload/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.