$filename = $_FILES['data']['tmp_name'];
$handle = fopen($filename, 'r');
$result = input_csv($handle); //解析csv
$length = count($result);
for ($i = 0; $i < $length; $i++) {
$ip = $result[$i][0];
$port = $result[$i][1];
//...
$data = array(
"ip" => $ip,
"port" => $port,
//...
);
$count = $Property->where($where)->find();
if($count){
$query = $Property->where($where)->save($data);
}else{
$query = $Property->add($data);
}
}
fclose($result);
$this->success('导入成功!');
exit();
上传CSV文件,执行后就报错了,求大神支招
ps:必须要判定IP+端口唯一,存在则覆盖,不存在则添加。
两种,一种是设置超时时间限制,还有一种就是把它转化成sql最后拿到数据库执行,我推荐第二种,这种性能好