Reputation: 4377
I have an array which contains a number of file names without extensions (below, the numbers are the name of the files):
[1] => 214
[2] => 12
[3] => 2763
[4] => 356
[5] => 87
I would like to delete these files from the server without knowing their extensions (which could be .jpg .JPG .GIF .jpeg, etc).
I tried using GLOB but I don't understand how to teach PHP to use wildcards and in the same time get the name of the files from the array.
Upvotes: 2
Views: 2271
Reputation: 11061
Assuming $names
is your array:
$path = "../pictures/";
foreach ($names as $name) {
foreach (glob($path . $name . '*') as $filename) {
unlink(realpath($filename));
}
}
Upvotes: 1