How can I delete the contents of a folder with PHP?
<p>I can't seem to get this function to delete all my files and folders in a specific directory can someone help me fix this problem?</p>

<p>Here is my code.</p>

<pre><code>$apps = 9;
$dirname = './members/' . $apps . '/';
function delete_directory($dirname) {
   if (is_dir($dirname))
      $dir_handle = opendir($dirname);
   if (!$dir_handle)
      return false;
   while($file = readdir($dir_handle)) {
      if ($file != "." &amp;&amp; $file != "..") {
         if (!is_dir($dirname."/".$file))
            unlink($dirname."/".$file);
         else
            delete_directory($dirname.'/'.$file);    
      }
   }
   closedir($dir_handle);
   rmdir($dirname);
   return true;
}
</code></pre>
