点击输入类型提交不会触发

我的代码遇到问题,我想创建一个上传按钮来上传我的.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');

有什么建议或建议吗?谢谢。

wsp0988 回答:点击输入类型提交不会触发

自动加载codeigniter文件中的第一个加载表单助手或手动加载

$autoload['helper'] = array('url'); // autoload
$this->load->helper->('form'); // manually loading form helper

您最好使用此

$attributes = array('enctype' => 'multipart/form-data');
echo form_open('index.php/fin/cost_control/workingcanvas/import',$attributes);

<your upload form code>

<?php echo form_close(); ?>

代替标签

更多信息:https://codeigniter.com/user_guide/helpers/form_helper.html

本文链接:https://www.f2er.com/3168264.html

大家都在问