简体   繁体   中英

How to take first file name from a folder and delete it in PHP

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.

Solved.

I used:

$files = glob($path_to_gallery . '/*.{jpg,png,gif}', GLOB_BRACE);
   foreach($files as $file) {
   unlink($file);
   break;
   }
$path = 'full_path/gallery/';
$dir = opendir($path);
while ($dir && ($file = readdir($dir)) !== false) {
    unlink($path.$file);
    break;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM