douxu0550 2017-05-02 11:41
浏览 72
已采纳

Codeigniter文件上传问题

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
     }
  }
  • 写回答

2条回答 默认 最新

  • doupa1883 2017-05-02 19:36
    关注

    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();
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀