Non funge...
questo è il codice

if ($handle = opendir($_SERVER['DOCUMENT_ROOT']."/images")){
while ($file = readdir($handle)){
if ($file != "." & $file != "..")

$files[]=$file;

}
}
mysql_select_db($database, $db);
$array = array();
$query = mysql_query( "SELECT photo,photo2 from foto");
while ($row = mysql_fetch_assoc($query) ) {
$array['photo'][] = $row['photo'];
$array['photo2'][] = $row['photo2'];

}


if(isset($_REQUEST[invia])){
foreach ($files as $f) {
if (!in_array($f, $array)) {
unlink($f);
}
}

}