html
选择文件
num_iid
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');
}