codeigniter - 输入类型提交点击时不会触发
问题描述
我的代码有问题,我想创建一个上传按钮来上传我的 .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 ,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');
有什么建议或建议吗?谢谢。
解决方案
首先在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
推荐阅读
- c# - 如何使用 MVVM 根据画布大小居中形状
- algorithm - 如何计算多个时间序列预测中的最佳时间间隔?
- java - 甲骨文决定在 Java 1.8v 之后支付 JMeter 的费用吗?
- java - 一类特定方法的切入点
- java - 为什么Java中不允许类中的隐式泛型?
- laravel - 等价于 Vue.js 中的 @foreach($variable as $key => $var)
- json - Kafka JDBC Sink 连接器为具有可选字段的模式的消息提供空指针异常
- ios - 如何修复 iOS10 安全区和 topLayoutGuide 问题?
- javascript - 快递哈巴狗不通过
- angular - 地图修改未触发商店更新