Check if folder is empty in php

1) using glob()


if(count(glob("/tmp/*"))==0) {
    echo 'dir empty';
} else {
    echo 'not empty';
}

2) using scandir() – will also read hidden files


if(count(scandir("/tmp/*")) == 2) {
   echo 'dir empty';
} else {
   echo 'not empty';
}

Leave a comment

3 Comments.

  1. [MARKED AS SPAM BY ANTISPAM BEE | CSS Hack]Among the best to talk about I’l brand new for you to blogs and extremely relhsied you’re also site. Most certainly I’meters going to bookmark your website . You actually incredibly consist of enormous posts as well as evaluations. Thanks a lot intended for revealing your web site web site.

  2. OK first take a great appear at your self. What do you like what do you not like so a lot. Work on that which you do not like. But do not litesn to other men and women their opinions do not matter only yours does. Function on having the attitude that this really is who youe2€™re and if they done2€™t like it they can go to hell. 0Was this answer helpful?

  3. Considerably, this publish is really the sweetest on this notable theme. I harmonise together with your conclusions and will thirstily search forward to your incoming updates. Declaring thanks will not just be sufficient, for your phenomenal clarity with your writing. I will right grab your rss feed to stay informed of any updates. Admirable function and significantly success with your company dealings!  Please excuse my poor English as it truly is not my 1st tongue.