首页 文章

codeigniter do_upload在ubuntu服务器上缺少参数1

提问于
浏览
0

我有一个关于codeigniter的问题,为什么我在do_upload excel文件上缺少参数,在localhost上工作但是在复制到linux服务器后它有这样的错误:

遇到PHP错误严重性:警告消息:章节:: do_upload缺少参数1,在第19行的/var/www/html/myfolder/application/controller/chapter.php中调用并定义了文件名:contollers / chapter.php行号:32

我错过了这段代码?

这是我的查看代码:

<center>
</br>
</br>
<?php  echo form_open_multipart('chapter') . "\n"; ?>
<table>
  <tr>
  <td><input type="file" id="file_upload" name="userfile" size="20" /></td>
   <td valign="top" >
   <?php echo form_submit('submit', 'Upload'); ?></td>
 </tr>
</table>
<?php echo form_close(); ?>
<?php
if ($this->session->flashdata('msg_excel')){
?>
<div class="msg"><?php echo $this->session->flashdata('msg_excel'); ?></div>
<?php } ?>
</br>
</br>
</div>
</center>

mycontoller:

<?php
class Chapter extends CI_Controller {
 function __construct()
 {
   parent::__construct();
   $this->load->model('Querypage');
   $this->load->model('m_login');
   $this->load->helper(array('form', 'url', 'inflector'));
   $this->load->library('form_validation');
 }
 public function index()
 {
       if ($this->input->post('submit'))
       {   
$this->do_upload();
        $this->load->view('chapter');
}
  else
  {
   $this->load->model('m_jadwal','',TRUE);
   $user = $this->session->userdata('username');
   $data['pengguna'] = $this->m_login->dataPengguna($user);
   $data['kdsmtaktif'] = $this->m_login->smtaktif();
   $this->load->view('aka_v', $data);
   $this->load->view('chapter');
  }
 }

public function do_upload()
{
    $config['upload_path'] = './temp_upload/';
    $config['allowed_types'] = 'xls';

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

     if ( ! $this->upload->do_upload())
     {
            $data = array('error' => $this->upload->display_errors());
            $this->session->set_flashdata('msg_excel', 'Gagal Memasukkan data. Cek file anda, hanya .xls yang diperbolehkan.');
     }
     else
     {
            $data = array('error' => false);
            $upload_data = $this->upload->data();

            $this->load->library('excel_reader');
            $this->excel_reader->setOutputEncoding('CP1251');

            $file =  $upload_data['full_path'];
            $this->excel_reader->read($file);
            error_reporting(E_ALL ^ E_NOTICE);

            // Sheet 1
            $data = $this->excel_reader->sheets[0] ;
            $dataexcel = Array();
            for ($i = 8; $i <= $data['numRows']; $i++) {
               if($data['cells'][$i][1] == '') break;
               $dataexcel[$i-1]['data1'] = $data['cells'][$i][1];
             $dataexcel[$i-1]['data2'] = $data['cells'][$i][2];      
            $dataexcel[$i-1]['data3'] = $data['cells'][$i][3];
            }
    //cek data
    $check= $this->Querypage->search_chapter($dataexcel);
    if (count($check) > 0)
    {
      $this->Querypage->update_chapter($dataexcel);
      // set pesan
      $this->session->set_flashdata('msg_excel', 'update data success');
  }else{
      $this->Querypage->insert_chapter($dataexcel);
      // set pesan
      $this->session->set_flashdata('msg_excel', 'inserting data success');
  }
  }
        echo " <script>
            history.go(-2);
          </script>";
  }
}
?>

2 回答

  • 0

    在您的控制器中更改:

    public function do_upload($user, $kdsmt)  //on line 32
    

    至:

    public function do_upload()
    

    您没有在方法中使用任何参数,因此不需要它们 . 更重要的是,如果你已经使用函数声明了params并且没有给它们一个默认值,那么如果你没有传递任何东西,那么PHP将会出错 .

    希望这可以帮助!

  • 0

    替换:

    $this->upload->do_upload()
    

    至 :

    $this->upload->do_upload("userfile")
    

    其中 userfile 是文件输入的名称 .

    CodeIgniter上传:https://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

相关问题