Can anyone suggest the best way to empty a folder using PHP. I do not want to use the recursive approach. Is there any alternative and what is that function/approach?
Thanks
Can anyone suggest the best way to empty a folder using PHP. I do not want to use the recursive approach. Is there any alternative and what is that function/approach?
Thanks
Have you tried using a combination of array_map
, unlink
and glob like this :
array_map('unlink', glob("/path/to/folder/*"));
Credits to Stichoza's answer
$files = glob('path/to/temp/*'); // get all file names
foreach($files as $file){ // iterate files
if(is_file($file))
unlink($file); // delete file
}