delete all files in folder on server

kevin wood 0 Tallied Votes 233 Views Share

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);
}
arijitdas 0 Newbie Poster

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

timmmay 0 Newbie Poster

@arijitdas:
did you mean

$dir = "your/directory/";
$filename = "test.doc";
unlink ($dir.$filename);
smithdp1 0 Newbie Poster

does the directory var have to be relative or server root?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.