문제

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.

도움이 되었습니까?

해결책

Assuming $names is your array:

$path = "../pictures/";
foreach ($names as $name) {
  foreach (glob($path . $name . '*') as $filename) {
    unlink(realpath($filename));
  }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top