If you are using Mac, or others systems that store information about the directory layout and etc, the function:
function empty_dir($dir) {
if (($files = @scandir($dir)) && count($files) <= 3)
return true;
else
return false;
}
Must have the count($files) comparing with the number of hidden files!
For example, I'm using Mac and the empty directory shows me three files: ".", ".." and ".DS_Store", so if I am planning to put the website online on my Mac, I've to count in the ".DS_Store" file!