Jump to content

Performing a document upload in PHP not working


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 {  
                if ($this->input->post('documents')) {
                    $documentPost = $this->input->post('documents');
                    $documentTitle = $this->input->post('doctitle');
                    $documentArray = array();
                    $c = 0;
                    foreach($documentPost as $dp){
                        $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');

                    if(count($documentArray) > 0){

Model Class:

function save_document($maindata){
    print_r($this->db->last_query()); die();
    return $this->db->insert_id(); 

function insert_listing($maindata){
    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. Are you sure you have something important to add to it?

Join the conversation

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

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.