2014-11-25 115 views
0

我有一个关于笨,为什么我有do_upload缺少参数问题excel文件,在本地主机上它的工作,但拷贝到Linux服务器后,有错误是这样的:笨do_upload缺少参数1 Ubuntu的服务器上

遇到PHP错误严重性:警告消息:缺少 参数1 for chapter :: do_upload,在 /var/www/html/myfolder/application/controller/chapter.php调用第19行 和定义的Filename: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>"; 
    } 
} 
?> 
+0

如何修复,什么是标签,如果你不使用它,我必须删除 – 2014-11-25 04:47:52

+0

要么改变'公共职能do_upload($用户,$ kdsmt)'来'公共职能do_upload()' .. – 2014-11-25 04:54:40

+0

但它仍然有同样的错误,像我的问题 – 2014-11-25 06:16:07

回答

0

在你的控制人变更情况:

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

要:

​​

你没有在你的方法中使用任何参数,所以没有必要拥有它们。更重要的是,如果你有一个函数声明params,并且不给它们一个默认值,那么如果你没有通过任何东西传递给它们,PHP将会发生错误。

希望这会有所帮助!

+0

是做到了这一点,但不改变我的错误 – 2014-11-25 10:16:31

+0

而错误肯定仍然说第19和32行? – 2014-11-25 10:18:41

+0

yap,那是真的 – 2014-11-25 13:15:39