我的代码遇到问题,我想创建一个上传按钮来上传我的.xlsx文件,但是即使单击它也不会触发。
我的view.php:
<form action="<?php echo base_url("index.php/fin/cost_control/workingcanvas/import"); ?>" method="post" id="import_form" enctype="multipart/form-data">
<p><label>Pilih File Excel</label>
<input type="file" name="file" id="file" required accept=".xls,.xlsx" /></p>
<br />
<input type="submit" id="import" name="import" value="Import" class="btn btn-info" />
</form>
我的控制器:
public function import(){
include APPPATH.'third_party/PHPExcel/PHPExcel.php';
$excelreader = new PHPExcel_Reader_Excel2007();
$loadexcel = $excelreader->load('excel/'.$this->filename.'.xlsx');
$sheet = $loadexcel->getactiveSheet()->toArray(null,true,true);
$numrow = 1;
foreach($sheet as $row){
if($numrow > 1){
array_push($data,array(
'nis'=>$row['A'],'nama'=>$row['B'],'jenis_kelamin'=>$row['C'],'alamat'=>$row['D'],));
}
$numrow++;
}
$this->SiswaModel->insert_multiple($data);
redirect("Siswa");
}
和我的模特:
public function insert_multiple($data){
$this->db->insert_batch('siswa',$data);
}
我尝试在自动加载中添加一些部分,例如
$ autoload ['helper'] = array('url','form','file');
有什么建议或建议吗?谢谢。