title: How can I use PHP to check if a directory is empty?
body: <p>I am using the following script to read a directory. If there is no file in the directory it should say empty. The problem is, it just keeps saying the directory is empty even though there ARE files inside and vice versa.</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  $pid = $_GET[&quot;prodref&quot;];
  $dir = '/assets/'.$pid.'/v';
  $q   = (count(glob(&quot;$dir/*&quot;)) === 0) ? 'Empty' : 'Not empty';
      
  if ($q==&quot;Empty&quot;) 
      echo &quot;the folder is empty&quot;; 
  else
      echo &quot;the folder is NOT empty&quot;;
  ?&gt;
  </code></pre>