html
<form action="{$excelurl}" method="post" enctype="multipart/form-data">
<br>
<br><br>
<table width="100%">
<tr>
<td class="tb_lable" style="width: 100px">选择文件</td>
<td>
<input type="file" name="force">
</td>
</tr>
<tr>
<td class="tb_lable" style="width: 100px">num_iid</td>
<td>
<input type="number" name="num_iid">
</td>
</tr>
<tr>
<td class="tb_lable"></td>
<td>
<br> <input id="sub_btn" type="submit" name="submit" value="导入" class="btn btn-primary" style="border-radius:5px;"/>
</td>
</tr>
</table>
</form>
<?php
if ($_POST['submit']) {
# code...$force = $_GPC['force'];
$file = $_FILES['force'];
if( $file['name'] && $file['error'] == 0){
$type = @end( explode('.', $file['name']));
$type = strtolower($type);
if( !in_array($type, array('xls','xlsx')) ){
message('文件类型错误!', '', 'error');
}
if(!$_POST['num_iid']){
message('num_iid不能为空!', '', 'error');
}
//开始导入
set_time_limit(0);
include_once IA_ROOT . '/framework/library/phpexcel/PHPExcel.php';
/** PHPExcel_IOFactory */
include_once IA_ROOT . '/framework/library/phpexcel/PHPExcel/IOFactory.php';
if( $type == 'xls' ){
$inputFileType = 'Excel5'; //这个是读 xls的
}else{
$inputFileType = 'Excel2007';//这个是计xlsx的
}
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($file['tmp_name']);
$objWorksheet = $objPHPExcel->getActiveSheet();//取得总行数
$highestRow = $objWorksheet->getHighestRow();//取得总列数
for ($row = 2;$row <= $highestRow;$row++){
$code = $objWorksheet->getCellByColumnAndRow(0, $row)->getValue();
pdo_insert('ka_ulie',array( 'num_iid' => $_POST['num_iid'] , 'xulie' => $code, 'status'=>0));
}
message('数据添加成功', $this->createWebUrl('Xulie'));
}
message('文件上传失败!', '', 'error');
}