codice:
$filesTutti = glob('path/*.*');
$filesDaNonCancellare = glob('path/*.{ext1,ext2,ext3}', GLOB_BRACE);
$filesDaCancellare = array_diff($filesDaNonCancellare, $filesTutti); 
foreach ($filesDaCancellare as $filename) {
  unlink($filename);
}