[英]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.
我有名为: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.
到目前为止,我知道我应该使用unlinke($ file)函数。 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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.