-3

How can I delete all the files in a folder using php/javascript. For example, this is what I am trying to do in php: using unlink function

Nitheesh K P
  • 1,090
  • 8
  • 17

2 Answers2

3

use

array_map('unlink', glob("some/dir/*.txt"));

this will delete all txt files in the directory for example

Att3t
  • 466
  • 2
  • 8
1

This will give you all the files including hidden files

$files = glob('some/directory/{,.}*', GLOB_BRACE);
foreach($files as $file){
if(is_file($file))
  unlink($file);
}
Bhavya Shaktawat
  • 2,504
  • 1
  • 13
  • 11