Delete or flush all files

You want to delete or flush all the files from a particular folder location using PHP.

Which of these code snippets can be used to achieve this objective?

Note: Assume folder path is “path/to/temp/”.

Options

1.$files = glob(‘path/to/temp/*’);

foreach($file in $files){

if(is_file($file))

unlink($file);

}

2.$files = glob(‘path/to/temp/*’);

foreach($files as $file){

if(is_file($file))

unlink($file);

}

3.$files = glob(‘path/to/temp/*’);

foreach($files as $file){

if(is_file($file))

delete($file);

}

4.$files = glob(‘path/to/temp/*’);

foreach($file in $files){

if(is_file($file))

delete($file);

}

Related Posts