0

I try to make a gallery. In a folder I have some duplicate pictures. I have pictures named: af_160112, af_160113, af_160114. I would like remove this first one. How to take the first picture in a folder and delete it? So far I have known that I should use unlinke($file) function. Thank you for your help.

Delicja
  • 193
  • 1
  • 8
  • 18

2 Answers2

2

Solved.

I used:

$files = glob($path_to_gallery . '/*.{jpg,png,gif}', GLOB_BRACE);
   foreach($files as $file) {
   unlink($file);
   break;
   }
Delicja
  • 193
  • 1
  • 8
  • 18
1
$path = 'full_path/gallery/';
$dir = opendir($path);
while ($dir && ($file = readdir($dir)) !== false) {
    unlink($path.$file);
    break;
}
Dezigo
  • 3,220
  • 3
  • 31
  • 39