Friday 8 April 2016

How to delete folder with contents in php

<?php

 function deletedir($dir) {
   $files = array_diff(scandir($dir), array('.','..'));
    foreach ($files as $file) {
      (is_dir("$dir/$file")) ? deletedir("$dir/$file") : unlink("$dir/$file");
    }
    return rmdir($dir);
  }  
  deletedir("filePath");
  deletedir("../file");

?>

No comments:

Post a Comment