Jump to content

Performing a document upload in PHP not working


KSI

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.