title: Select random file using OPENDIR()
body: <p>I have tried:</p>
  
  <pre><code>function random_pic($dir = '../myfolder') {
      $files = opendir($dir . '/*.*');
      $file = array_rand($files);
      return $files[$file];
  }
  </code></pre>
  
  <p>This function works using <code>glob()</code> but not opendir.</p>
  
  <p>This returns a failed to open directory error. I guess opendir cannot accept things like <code>*.*</code>? Is it possible to select all files in a folder and randomly choose one?</p>