<?$path=getcwd()."/temp";//存放图片目录$host="localhost";//主机名$dbuser="root";//登录数据库用户名$password="156";//密码$db="db";//数据库名称$table="table";//存放图片表的名称/*从数据中查询所有已经被用的图片名称,存储一个数组中假如为$pic*/$query="select pic * from ".$table;$link=mysql_query($host,$dbuser,$password);mysql_select_db($db,$link);$result=mysql_query($query);while($row=mysql_fetch_array($result)){ $pic=$pic.$row[pic];}$listArray=scandir($path);foreach($listArray as $item){ $isExist=false;foreach($pic as $datapic){ if($item==$datapic){$isExist=true;break;}}if($isExist==true){unlink($path."/".$item);echo"删除:".$item." ";}}?>