我有一个关于codeigniter的问题,为什么我在do_upload excel文件上缺少参数,在localhost上工作但是在复制到linux服务器后它有这样的错误:
遇到PHP错误严重性:警告消息:丢失 chapter :: 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>";
}
}
?>
答案 0 :(得分:0)
在您的控制器中更改:
public function do_upload($user, $kdsmt) //on line 32
要:
public function do_upload()
您在方法中没有使用params,因此无需使用它们。更重要的是,如果你已经使用函数声明了params并且没有给它们一个默认值,那么如果你没有通过任何东西,那么PHP将会出错。
希望这有帮助!
答案 1 :(得分:0)
替换:
$this->upload->do_upload()
到:
$this->upload->do_upload("userfile")
其中userfile
是文件输入的名称。
CodeIgniter上传:https://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html