2

I have a codeigniter application which basically accepts xls files, parse it and process on the data from the excel file.

Here is the code that I used for uploading the file.

When the form is submitted, the code below is executed. When I submit a file with small size, it is uploaded properly and is also processed. However, if I upload a file with a larger size, it gets uploaded, but isnt processed. I even get redirected to the upload form with the error "You did not select a file to upload."

Is this something which is caused by max_execution_time? PS: I have these three lines at the top of the controller

set_time_limit(0);
ini_set('memory_limit', '20000M');
ini_set('max_execution_time', 3000);

UPDATE : The file size I am trying to update is of 1.59 MB

Upload

public function do_upload() {
     $config['upload_path']   = './excel_files/';
     $config['allowed_types'] = 'xls|xlsx';
     $config['max_size']      = 100000;

     $this->load->library('upload', $config);
    //  upload failed, handle properly
     if ( ! $this->upload->do_upload('userfile')) {
        $error = array('error' => $this->upload->display_errors());
        $data = array('subview'=>'admin/upload_form','error'=>$error);
        $this->load->view('layout', $data);
     }

    //  upload success, record the file data
     else {
       $uploadData = $this->upload->data();

       $fileData = array(
                      'name'    =>  $uploadData['orig_name'],
                      'size'    =>  $uploadData['file_size'],
                      'stored_name' =>  $uploadData['file_name'],
       );

       $this->file_m->insert($fileData);

        $this->process($uploadData); // process the uploaded  file
     }
  }
8
  • have you used enctype="multipart/form-data" in form tag Commented May 2, 2017 at 11:47
  • @AmitGaud files with smaller size get uploaded. So it is quite obvious that the form uses multipart/form-data Commented May 2, 2017 at 11:48
  • is your filesize is greater then $config['max_size'] = 100000; KB ? Commented May 2, 2017 at 11:48
  • @VasimPadhiyar it is of 1.59 MB Commented May 2, 2017 at 11:49
  • what is your file size Commented May 2, 2017 at 11:49

2 Answers 2

2

It looks overriding code is not working.

set_time_limit(0);
ini_set('memory_limit', '20000M');
ini_set('max_execution_time', 3000);

Way 1:

Update the settings in php.ini file. Hope issue will be resolved.

max_execution_time = 259200
max_input_time = 259200
memory_limit = 300M
upload_max_filesize = 200M
post_max_size = 200M

Way 2:

.htaccess way

<IfModule mod_php5.c>
   php_value post_max_size 200M
   php_value upload_max_filesize 200M
   php_value memory_limit 300M
   php_value max_execution_time 259200
   php_value max_input_time 259200
   php_value session.gc_maxlifetime 1200
</IfModule>

verify the settings by creating a php info file. test_settings.php

<?php
    phpinfo();
?>
Sign up to request clarification or add additional context in comments.

Comments

1
function upload_it() {
    //load the helper
    $this->load->helper('form');
    $config['upload_path'] = 'application/views/uploads/';

    // set the filter image types
    $config['allowed_types'] = 'xls|xlsx';

    //load the upload library
    $this->load->library('upload', $config);

    $this->upload->initialize($config);

    $this->upload->set_allowed_types('*');

    $data['upload_data'] = '';

    //if not successful, set the error message
    if (!$this->upload->do_upload('userfile')) {
      $data = array('msg' => $this->upload->display_errors());

    } else { //else, set the success message
      $data = array('msg' => "Upload success!");

      $data['upload_data'] = $this->upload->data();

    }

    //load the view/upload.php
    $this->load->view('upload', $data);

  }

1 Comment

While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.