//文件导入式 批量添加关键词 elseif($dopost == 'fileKeywords') { if(is_uploaded_file($filename)) { $newFileName = date('YmdHis', time() ) .'.txt'; $newDirPath = $cfg_basedir . '/uploads/keywords'; $newFilePath = $newDirPath .'/'.$newFileName; //目录不存在则创建 if(!file_exists( $newDirPath )) { mkdir($newDirPath, 0777, true); } move_uploaded_file($filename, $newFilePath); //读取上传的文件 $handle = fopen($newFilePath, 'r') or ShowMsg("上传文件读取失败",-1); $keyArr = array(); if($handle) { while(!feof($handle)) { $buffer = fgets($handle, 4096); $buffer = str_replace(',', ',', $buffer); $buffer = str_replace(array("\n"), '', $buffer); $buffer = trim($buffer); if(!empty($buffer)) { $keyArr[] = explode(',', $buffer); } } fclose($handle); @unlink( $newFilePath ); } //取出数据库所有的关键词,和新添加关键词比较,如果新添加的关键字,数据中存在则过滤 $dsql->SetQuery( "SELECT `keyword` FROM `dede_keywords` " );//将SQL查询语句格式化 $dsql->Execute();//执行SQL操作 //通过循环输出执行查询中的结果 $dataKeyArr = array(); while($row = $dsql->GetArray() ) { $dataKeyArr[] = $row['keyword']; } //拼接mysql 语句 $i = 0; foreach($keyArr as $k => $v) { $key = trim( $v[0] ); //把读取txt文档的数据转utf-8编码 www.dedecms51.com $key = ($cfg_soft_lang != 'utf-8') ? iconv( "UTF-8", "gb2312//IGNORE" , $key) : $key; //如果数据库中存在该关键词,则跳出本次循环。 注意: keyword字段在数据库中长度16字符,需要更更长点 //ALTER TABLE `dede_keywords` CHANGE `keyword` `keyword` CHAR( 255 ) NOT NULL DEFAULT '' if( in_array( $key, $dataKeyArr ) ) continue; //拼接mysql语句 $rpurl = trim($v[1], ' '); $rank = trim($v[2], ' '); $sql = "INSERT INTO `dede_keywords` ( keyword, rank, sta, rpurl ) VALUES ( '{$key}', {$rank}, 1, '{$rpurl}')"; $res = $dsql->ExecuteNoneQuery2($sql); if( $res != -1) $i ++; } //如果导入的文件所有的关键词都添加过了,则停止执行; if(empty($i)) { ShowMsg("警告:你提交的关键词,早已经添加过了!!!",-1); die(); } else { ShowMsg("你成功导入{$i}条数据",-1); } } } //清空关键字表里的所有数据 else if($dopost == 'delAll') { $dsql->ExecuteNoneQuery('TRUNCATE TABLE `dede_keywords`') ? ShowMsg("你已成功清除所有的关键词!!", $ENV_GOBACK_URL ) : ShowMsg("清除关键词失败",-1) ; }
//删除选中的 function delSel() { var celements = document.getElementsByClassName('del'); for( i = 0; i < celements.length; i++ ) { if(!celements[i].checked) celements[i].checked = true; else celements[i].checked = false; } } function delAll () { if( confirm( '你确定要清空所有的关键词,清除以后不可恢复!!' ) ) { location.href="article_keywords_main.php?dopost=delAll"; } }继续找到
<form action="article_keywords_main.php" method="post" enctype="multipart/form-data"> <td width="40%" style="padding-left:10px;"> <strong>关键词维护</strong> <strong> </strong> <strong><input type="file" name="filename"></strong> <input type="hidden" name="dopost" value="fileKeywords" /> <strong><input type="submit" value="提交"></strong> </td> </form>继续找到
<td height="28" colspan="6"> <input type="button" name="dl1" class="coolbg np" value="反选" onClick="selAll()" /> <input type="button" name="dl2" class="coolbg np" value="保存更改" onClick="this.form.submit();" /> </td>改成
<td height="28" colspan="4"> <input type="button" name="dl1" class="coolbg np" value="反选" onClick="selAll()" /> <input type="button" name="dl2" class="coolbg np" value="保存更改" onClick="this.form.submit();" /> </td> <td height="28" align="center" > <input type="button" value="清空所有关键词" onClick="delAll()" /> <input type="button" name="dl1" class="coolbg np" value="删除全选" onClick="delSel()" /> </td>完成。
版权声明: 本站资源均来自互联网或会员发布,如果侵犯了您的权益请与我们联系,我们将在24小时内删除!谢谢!
转载请注明: 织梦dedecms如何批量导入关键词做内链优化