title: PHP Scandir returns extra periods
body: <p>So I am trying to build a script that scans a directory and returns random images to be used as backgrounds. </p>
  
  <p>The php looks like this:</p>
  
  <pre><code>$dir = "views/img/bg/";
  $dh  = opendir($dir);
  while (false !== ($filename = readdir($dh))) {
      $files[] = $filename;
  }
  
  $random_key = array_rand($files, 1);
  
  $random = $files[$random_key];
  </code></pre>
  
  <p>Then I am just using some simple jquery to attach the images as backgrounds: </p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function(){
  
      $("body").css( "background" , "url(http://'.$url_root.'/views/img/bg/'.$random.'), center center" );
  
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Everything works fine but the array of all the images in the background folder seems to be returning stuff like '.' or '..' instead of image names every once in a while. Im not sure what is going on - any ideas?</p>