-3

I need to delete the contents of plugin cache folder every 20 mins. I have a job planner (task planner) on my hosting. The problem is, that I need a php script, which will order to delete all the files within specified directory.

Please, help me with such one.

Thank You in advance to you all, who will answer!

1 Answers1

0

I think you have to try something like this and let us know if any error/warning. This is a recursive function to delete all files and sub-directory within a directory.

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

For details see Here

Riad
  • 3,822
  • 5
  • 28
  • 39