Example #1
0
 if ($_FILES['excel']['error'] != 0) {
     $message = 'ÉÏ´«Îļþʧ°Ü,error number(' . $_FILES['excel']['error'] . ')';
     OSAdmin::alert("error", $message);
 }
 // $file_name = $_FILES['excel']['name'];
 // $tmp = explode('-', $file_name);
 // if($name_map[$tmp[0]] !== $_POST['table']){
 // 	$error[$_POST['table']][] = '您所导入的表不是正确的表或命名有误!';
 // }elseif(isset($tmp[1]) && is_numeric($tmp[1])){
 $file = $_FILES['excel']['tmp_name'];
 $excel_array = ExcelReader::readXLS($file);
 if ($_POST['cover'] == 'on') {
     Complaint::delDataByMonth($_POST['table'], $tmp[1]);
 } else {
     $check = false;
     $check = Complaint::checkFirstLine($excel_array, $_POST['table']);
 }
 if ($check) {
     $error[$_POST['table']][] = $check['error'];
 } else {
     // TODO check if imported
     if ($excel_array) {
         array_shift($excel_array);
         $error[$_POST['table']] = array();
         $record_id = Complaint::recordTable($_FILES['excel']['name'], $table, $date, $province_id, $user_info['user_id']);
         foreach ($excel_array as $key => $value) {
             $r = Complaint::save($value, $table, $date, $province_id, $record_id);
             if (!$r) {
                 file_put_contents('../error_' . date('Y-m-d') . '.log', date('Y-m-d H:i:s') . ' ' . $_FILES['excel']['name'] . ' \'' . implode("','", $value) . "'\n", FILE_APPEND);
                 $error[$_POST['table']][] = '\'' . implode("','", $value) . "'<br>";
             }