【问题标题】:codeigniter do_upload is missing argument 1 on ubuntu servercodeigniter do_upload 在 ubuntu 服务器上缺少参数 1
【发布时间】:2014-11-25 04:42:39
【问题描述】:

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

遇到 PHP 错误 严重性:警告消息:丢失 Chapter::do_upload 的参数 1,调用 /var/www/html/myfolder/application/controller/chapter.php 第 19 行 并定义文件名: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>

我的控制器:

<?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>";
  }
}
?>

【问题讨论】:

  • 如何修复,我必须删除什么标签
  • 如果您不使用它,请将 public function do_upload($user, $kdsmt) 更改为 public function do_upload()..
  • 但它仍然有像我的问题一样的错误

标签: php codeigniter phpexcel phpexcelreader


【解决方案1】:

在您的控制器更改中:

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

收件人:

public function do_upload()

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

希望这会有所帮助!

【讨论】:

  • 而且错误肯定还在说第19行和第32行?
  • 如果第 19 行只是 $this-&gt;do_upload(); 而第 32 行只是 public function do_upload()。那么您使用的是哪个 PHP 版本,您是否知道是否有任何缓存,例如OPCache?因为这个错误绝对不应该被重新生成。
  • 我很喜欢您的评论,并且 $this->load->library('upload', $config); 错误仍然存​​在为什么在这个区域出错?上传库很好地包含在 codeigniter 中
  • 出现新错误?你可以在你的问题中发布它吗?
【解决方案2】:

替换:

$this->upload->do_upload()

到:

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

userfile 是您的文件输入的名称。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多