3

I have a folder with images.

As example:

z_1.jpg
z_2.jpg
z_3.jpg
//...

I want to delete every image with prefix z_*.jpg. How can I do that?

unlink('z_*.jpg'); ?
Rizier123
  • 58,877
  • 16
  • 101
  • 156
Arriba
  • 305
  • 2
  • 3
  • 14

1 Answers1

7

You need the exact filename to unlink() a file. So just use glob() to get all files which you want to grab. Loop through the returned array and delete the files, e.g.

<?php

    $files = glob("z_*.jpg");

    foreach($files as $file)
        unlink($file);

?>
Rizier123
  • 58,877
  • 16
  • 101
  • 156