phpcmsV9清理数据库和附件冗余代码

作者:笨小孩 发布于:2012-10-18 16:19 分类:网站程序

<pre><?php
/*清理数据库记录冗余
*直接运行下面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(‘<br />’,$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);
?>

标签: PHPCMS

发表评论:

手机版 | 
Copyright © 2012 lamp46.com All Right Reserved. sitemap