KSI Posted November 20, 2021 Share Posted November 20, 2021 Currently I'm using codeigniter 3.0 and I have a multiple document upload tab in my add page. Here the user can write the title of the document and upload a document and they can select the add button to add more documents. But I cannot store these document in my database when I click on the save button. Here is my current code: View class: <td width="45%"><input type="text" name="doctitle[]" placeholder="Title"></td> <td><input type="file" name="documents[]"></td> <td width="1%"><a class="btn btn-success" id="addobj" href="javascript:void(0)">Add </a></td> Controller Class: if ($this->form_validation->run() == FALSE) { $main['page'] = 'crm/listings/add'; $this->load->view('crm/index', $main); }else { $maindata=array('clients_id'=>$this->session->userdata('clientsessid')); $insertid=$this->listings_model->insert_listing($maindata); if($insertid){ if ($this->input->post('documents')) { $documentPost = $this->input->post('documents'); $documentTitle = $this->input->post('doctitle'); $documentArray = array(); $c = 0; foreach($documentPost as $dp){ if($this->web_upload->do_upload('documents')) { $filedata=$this->web_upload->data(); $dp=$filedata['file_name']; } $documentArray[$c]['listings_id']= $insertid; $documentArray[$c]['title']= $documentTitle; $documentArray[$c]['document']= $dp; $documentArray[$c]['added_date']=date('Y-m-d H:i:s'); $documentArray[$c]['added_by']= $this->session->userdata('user_id'); $c++; } if(count($documentArray) > 0){ $this->listings_model->save_document($notesArray); } } redirect('listings/sales'); } Model Class: function save_document($maindata){ $this->db->insert_batch("crm_property_docs",$maindata); print_r($this->db->last_query()); die(); return $this->db->insert_id(); } function insert_listing($maindata){ $this->db->insert("crm_listings",$maindata); $prime=$this->db->insert_id(); return $prime; } Now I have added a print_r($this->db->last_query()); die(); statement in my save_document model so if it is being executed it should end the process there but it doesnt end my process, it just fills in all the data values in my database except for the documents data, which means this model is never being called and I'm not sure if I'm using the right method to upload these documents in my database. Quote Link to comment https://forums.phpfreaks.com/topic/314253-performing-a-document-upload-in-php-not-working/ Share on other sites More sharing options...
Barand Posted November 20, 2021 Share Posted November 20, 2021 https://www.php.net/manual/en/features.file-upload.post-method.php Quote Link to comment https://forums.phpfreaks.com/topic/314253-performing-a-document-upload-in-php-not-working/#findComment-1592293 Share on other sites More sharing options...
kicken Posted November 24, 2021 Share Posted November 24, 2021 On 11/20/2021 at 8:55 AM, KSI said: if(count($documentArray) > 0){ $this->listings_model->save_document($notesArray); } Do you maybe mean $documentArray and not $notesArray there? Quote Link to comment https://forums.phpfreaks.com/topic/314253-performing-a-document-upload-in-php-not-working/#findComment-1592316 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.