How to delete a file if exists in PHP?
First, define a vari
able that stores the path to the directory in which you want to delete files.
Second, use the
glob()function to search for all files in the directory $dir that has the *.tmp extension and pass it result to the
array_map()function to delete the files.
The following example uses the
unlink()function to delete the readme.txt file: