将需要上传文件前的原表中的数据先读出存入一个数组$noarr:
使用getField实现,例如:
$noarr = $model->getField('no',true); //使用getField读取字段no存入到数组$noarr;
读取上传文件中的数据,从第一行开始读取,检查读取的该行数据是否在数组中存在,如果不存在,则写入二维数组$arr,并把数据追加到数组$noarr中,如果存在,继续读取下一行。
用in_array检测数据是否在数组中存在,例如:
$arr = array();
if(in_array($row['no'], $arrNo)){
$file="./Public/uploaddir/log.txt";
$current.=$row['no'].'存在'.PHP_EOL;
file_put_contents($file, $current); //将$current写入$file下的目录的文件里;
}else{
$arrNo[]=$row['no'];
$arr[]=$row;
$file="./Public/uploaddir/log.txt";
$current.= $row['no'].'导入成功'.PHP_EOL;
file_put_contents($file, $current);
}