Loading... /*清理数据库记录冗余 *直接运行下面sql语句 *delete v9_news a from v9_news a ,(select * from v9_news group by title having count(1)>1) b where a.title=b.title and a.catid=b.catid and a.id>b.id; // *delete from v9_news_data where id NOT IN (select id from v9_news); *delete from v9_hits where hitsid NOT IN (select concat(‘c-1-’,id) from v9_news); */ //清理附件冗余 //注意附件的路径和文章内容中图片的规律。 include ‘include/db.inc.php’ ;//连接数据库 include ‘include/mapping.php’ ;//分类id和附件目录的映射文件 $cat = ‘dianziqin’; $fold = “list_{$cat}”; $picdir= “uploadfile/{$mapping[$fold]}/”;//读取数据目录 $dirpic = scandir($picdir); array_shift($dirpic);array_shift($dirpic); //var_dump($dirpic); $sql = “select d.content from v9_news_data d, v9_news n where d.id=n.id and n.catid=’{$mapping[$cat]}’”; $rs = mysql_query($sql); //var_dump($sql); $cntpic = array(); while($row = mysql_fetch_assoc($rs)){ $picarr = explode(‘ ’,$row['content']); array_pop($picarr); foreach($picarr as $k=>$v){ $cntpic[] = substr($v,29,21); } unset($picarr); } //var_dump($cntpic); $rubbish = array_diff($dirpic,$cntpic); var_dump($rubbish); foreach($rubbish as $v){ unlink($picdir.$v); //exit; } unset($dirpic);unset($cntpic);unset($rubbish); ?> Last modification:September 21, 2022 © Allow specification reprint Like 如果觉得我的文章对你有用,请随意赞赏