后端代码
public function adddao() { if (IS_POST) { $filename = input('post.filename/s'); !empty($filename) && @unlink($filename); $split_type = input('split_type/s', ' '); $content = input('content/s', ''); $check_card = input('check_card/d', 0); $arr = explode(PHP_EOL, trim($content)); $count = count($arr); //去除数组两端的空白字符 $arr = array_map(function ($v) { return trim(str_replace(chr(194) . chr(160),' ', $v)); }, $arr); if ($check_card == 1) { $arr = array_values(array_unique($arr)); } if ($split_type == '0') { //自动识别 if (strpos($arr[0], " ") !== false) { $split_type = " "; } elseif (strpos($arr[0], ",") !== false) { $split_type = ","; } elseif (strpos($arr[0], "|") !== false) { $split_type = "|"; } elseif (strpos($arr[0], "----") !== false) { $split_type = "----"; } else { $split_type = ""; } } $cards = []; foreach ($arr as $v) { if (!empty($split_type)) { $card = explode($split_type, $v); } else { $card = [$v, '']; } if (isset($card[0])) { $card[0] = trim(html_entity_decode($card[0]), chr(0xc2) . chr(0xa0)); } else { continue; } if ($card[0] === '') { continue; } if (strlen($card[0]) > 255) { continue; } // if(validateURL($card[0])) {//禁止url // $this->error('虚拟卡内容不能包含链接'); // } $number = $card[0]; if (isset($card[1])) { $card[1] = trim(html_entity_decode($card[1]), chr(0xc2) . chr(0xa0)); } else { continue; } if ($card[1] !== '') { if (strlen($card[1]) > 255) { continue; } $secret = $card[1]; } else { $secret = ''; } // 检查重复 if ($check_card == 1) { $isExist =$this->db->where(['number' => $number, 'secret'=>$secret])->find(); if ($isExist) { continue; } } $cards[] = [ 'number' => $number, 'secret' => $secret, 'status' => 1, // 未使用 ]; } if(!empty($cards)) { $res = $this->db->insertAll($cards); if (false !== $res) { $this->success("操作成功,有效新增".$res.'条数据', weapp_url('Iplist/Iplist/index')); }else{ $this->error("操作失败"); } }else{ $this->success('虚拟卡内容格式不正确, 或卡密已存在', weapp_url('Iplist/Iplist/index')); } exit; } $this->assign('info', $info); return $this->fetch('adddao'); }
前端代码:
<form class="form-horizontal" id="post_form" action="{:url('Ka/Ka/adddao')}" method="post"> <div class="ncap-form-default"> <dl class="row"> <dt class="tit"> <label>导入格式</label> </dt> <dd class="opt"> <div class="onoff"> <select name="split_type" class="form-control"> <option value="0">自动识别</option> <option value=" ">用“ ”分隔</option> <option value=",">用“,”分隔</option> <option value="|">用“|”分隔</option> <option value="----">用“----”分隔</option> <option value="">不分隔</option> </select> </div> </dd> </dl> <dl class="row"> <dt class="tit"> <label>检查重复卡</label> </dt> <dd class="opt"> <div class="onoff"> <label for="target1" class="cb-enable selected">是</label> <label for="target0" class="cb-disable ">否</label> <input id="target1" name="check_card" value="1" type="radio" checked="checked"> <input id="target0" name="check_card" value="0" type="radio"> </div> </dd> </dl> <dl class="row"> <dt class="tit"> <label for="title"><em>*</em>ip+密码列表</label> </dt> <dd class="opt"> <textarea style="width:500px; height:350px;" name="content" id="content" placeholder="如:AAAAAAAAAAA BBBBBBBBBBBB"></textarea> <span class="err"></span> <p class="">提示:不允许为空,一行代表一个!</p> </dd> </dl> <div class="bot" style="margin-top:10px;"> <input type="hidden" name="filename" id="filename" value=""> <a href="JavaScript:void(0);" onclick="checkForm();" class="ncap-btn-big ncap-btn-green" id="submitBtn">确认提交</a> </div> </div> </form> </div> <script type="text/javascript"> // 判断输入框是否为空 function checkForm(){ if ($("#content").val() == '') { showErrorMsg('ip+密码列表不能为空!'); $('#content').focus(); return false; } layer_loading('正在处理'); $('#post_form').submit(); } </script>
标签: thinkphp
版权声明:本站只提供资源,不提供技术支持!如有侵权请发邮件至:geekbt@163.com ,我们会第一时间进行审核处理! 本站资源大多来自网络,版权争议与本站无关,所有资源仅限用于学习和研究目的。不得将其用于商业或者非法用途,否则,一切后果请用户自负。我们不保证资源的长久可用性,通过使用本站资源随之而来的风险与本站无关。您必须在下载后的24小时内,从您的设备中彻底删除所下资源。如果您喜欢该资源,请支持正版软件/程序,购买注册,得到更好的正版服务。
还木有评论哦,快来抢沙发吧~