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.

3
  • 1
    unlink is the correct function. I'm not sure what your problem is?
    – Corbin
    Commented Jun 6, 2012 at 5:55
  • For search filename use opendir php.net/manual/en/function.opendir.php
    – Sergey
    Commented Jun 6, 2012 at 6:01
  • Sorry, I am not precise. I try to use foreach loop and dir function but I do something wrong. I will edit my first post.
    – Delicja
    Commented Jun 6, 2012 at 6:10

2 Answers 2

2

Solved.

I used:

$files = glob($path_to_gallery . '/*.{jpg,png,gif}', GLOB_BRACE);
   foreach($files as $file) {
   unlink($file);
   break;
   }
1
$path = 'full_path/gallery/';
$dir = opendir($path);
while ($dir && ($file = readdir($dir)) !== false) {
    unlink($path.$file);
    break;
}
1
  • Thanks. I don't know what I'm doing wrong. I got (dots): .. not name of jpg file. I use glob.
    – Delicja
    Commented Jun 6, 2012 at 8:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.