0

this code will delete all the files from a directory on the server. be careful when using this as it will delete everything in the directory so use it wisely or make sure you have backups if it is implemented on the wrong directory.

it works by searching for all the file which have a full stop (.) in side the file name. it does not matter what the extension is it will be deleted.

$dir = 'your/directory/';
foreach(glob($dir.'*.*') as $v){
    unlink($v);
}
4
Contributors
3
Replies
10
Views
9 Years
Discussion Span
Last Post by smithdp1
0

How to delete a particular file the program deletes all the files with the same extension is there any way to delete a particular file,say by assigning the file name to a varialble and call the variable inside the glob function

if is please please do reply

0

@arijitdas:
did you mean

$dir = "your/directory/";
$filename = "test.doc";
unlink ($dir.$filename);
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.