数据库附件查询对比!


<?
header("Content-Type:text/html; charset=utf-8");
@require "../data/config.php";
//连接MySQL数据库
$conn = mysql_connect($db_server,$db_username,$db_password) or die("无法连接数据库!");
mysql_select_db($db_name);
$sql = 'SELECT * FROM `boblog_upload`'; //查询表
$result = mysql_query($sql,$conn);
mysql_close($conn); //关闭数据库链接
while($rs= mysql_fetch_array($result)) {
if (@fopen('../'.$rs['filepath'],'r')) {
$dbarr[] = $rs['filepath'];//存储路劲就可以了,
}
}
$hide = array('1'=>'.','..','.ddrr_album','index.php');
//遍历附件目录
$dh = opendir('../attachment/');
while ($file = readdir($dh)) {
if(!in_array($file,$hide)) {
$filedir = '../attachment/'.$file; //每一个元素前都加上目录.
}
if (@fopen($filedir,'r')) { //判断文件是否存在
$Yes_file[] = $filedir;
$filedir = 'attachment/'.$file;
$dirarr[] = $filedir;
//echo $filedir; //返回存在的文件
}
}
closedir($dh); //关闭目录
$arr = array_intersect($dbarr, $dirarr); //求两数组的交集,得到$dbarr与$dirarr都存在的元素,$dbarr与$dirarr顺序没有限制
$arr1 = array_diff($dbarr, $arr); //返回$dbarr中存在,但$arr中存在的元素
$arr2 = array_diff($dirarr, $arr); //返回$dirarr中存在,但$arr中存在的元素

echo "<table align='center' width='80%' style='border:1px solid #d0d0d0;'>\n";
echo "<tr>\n";
echo "<td width='35%' style=\"border-bottom:1px solid #d0d0d0;border-right:1px solid #d0d0d0;\">数据库中的记录</td>\n";
echo "<td width='35%' style=\"border-bottom:1px solid #d0d0d0;border-right:1px solid #d0d0d0;\">文件夹中的记录</td>\n";
echo "<td width='30%' style=\"border-bottom:1px solid #d0d0d0;\">存在差异的记录</td>\n";
echo "</tr>\n";
foreach($arr as $key=>$rs){
echo "<tr>\n";
echo "<td style=\"border-bottom:1px solid #d0d0d0;border-right:1px solid #d0d0d0;\">$rs</td>\n";
echo "<td style=\"border-bottom:1px solid #d0d0d0;border-right:1px solid #d0d0d0;\">$rs</td>\n";
echo "<td style=\"border-bottom:1px solid #d0d0d0;\">相等</td>\n";
echo "</tr>\n";
}
foreach($arr1 as $key=>$rs){
echo "<tr>\n";
echo "<td style=\"border-bottom:1px solid #d0d0d0;border-right:1px solid #d0d0d0;\">$rs</td>\n";
echo "<td style=\"border-bottom:1px solid #d0d0d0;border-right:1px solid #d0d0d0;\">无</td>\n";
echo "<td style=\"border-bottom:1px solid #d0d0d0;\">$rs</td>\n";
echo "</tr>\n";
}
foreach($arr2 as $key=>$rs){
echo "<tr>\n";
echo "<td style=\"border-bottom:1px solid #d0d0d0;border-right:1px solid #d0d0d0;\">无</td>\n";
echo "<td style=\"border-bottom:1px solid #d0d0d0;border-right:1px solid #d0d0d0;\">$rs</td>\n";
echo "<td style=\"border-bottom:1px solid #d0d0d0;\">$rs</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
?>
文章附属文件

文件名称: 20180105115112025878.jpg

文件大小:712.26 KB

文件签名:7109B112A115520E4693D23B617C58E6EB0A2718