//文件導入式 批量添加關鍵詞 elseif($dopost == 'fileKeywords') { if(is_uploaded_file($filename)) { $newFileName = date('YmdHis', time() ) .'.txt'; $newDirPath = $cfg_basedir . '/uploads/keywords'; $newFilePath = $newDirPath .'/'.$newFileName; //目錄不存在則創(chuàng)建 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 ); } //取出數(shù)據(jù)庫所有的關鍵詞,和新添加關鍵詞比較,如果新添加的關鍵字,數(shù)據(jù)中存在則過濾 $dsql->SetQuery( "SELECT `keyword` FROM `dede_keywords` " );//將SQL查詢語句格式化 $dsql->Execute();//執(zhí)行SQL操作 //通過循環(huán)輸出執(zhí)行查詢中的結果 $dataKeyArr = array(); while($row = $dsql->GetArray() ) { $dataKeyArr[] = $row['keyword']; } //拼接mysql 語句 $i = 0; foreach($keyArr as $k => $v) { $key = trim( $v[0] ); //把讀取txt文檔的數(shù)據(jù)轉utf-8編碼 www.dedecms51.com $key = ($cfg_soft_lang != 'utf-8') ? iconv( "UTF-8", "gb2312//IGNORE" , $key) : $key; //如果數(shù)據(jù)庫中存在該關鍵詞,則跳出本次循環(huán)。 注意: keyword字段在數(shù)據(jù)庫中長度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 ++; } //如果導入的文件所有的關鍵詞都添加過了,則停止執(zhí)行; if(empty($i)) { ShowMsg("警告:你提交的關鍵詞,早已經(jīng)添加過了?。?!",-1); die(); } else { ShowMsg("你成功導入{$i}條數(shù)據(jù)",-1); } } } //清空關鍵字表里的所有數(shù)據(jù) else if($dopost == 'delAll') { $dsql->ExecuteNoneQuery('TRUNCATE TABLE `dede_keywords`') ? ShowMsg("你已成功清除所有的關鍵詞?。?quot;, $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"; } }繼續(xù)找到
<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>繼續(xù)找到
<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>完成。
版權聲明: 本站資源均來自互聯(lián)網(wǎng)或會員發(fā)布,如果侵犯了您的權益請與我們聯(lián)系,我們將在24小時內(nèi)刪除!謝謝!