Delete folder and contents with php

0

I am using the following command:

unlink("Arquivos/$token"); 

Is this correct? Does it delete all files and subfolders?

It is giving the following error:

Warning: unlink(Arquivos/5b6a7a075e26664fd69e23f60c5d55bc): Operation not permitted in /Library/WebServer/Documents/Sites/Sistema/Paginas/Servidor/Todos_Clientes.php on line 90
    
asked by anonymous 13.07.2016 / 15:42

1 answer

3

You can use this PHP function that deletes the folder and its internal files:

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

    delTree('caminho/da/pasta/aqui');

This function is in the php manual

I hope I have helped.

    
13.07.2016 / 15:52