<?php $directory = "/somedir"; if(is_dir($directory) && ($handle = @opendir($directory))) { // ....... } else { die('Could not open directory'); } ?>