PHP-Codeigniter-如何使用某些名称删除文件 [英] PHP - Codeigniter - How to delete file with some name
问题描述
我有以下名称的图像文件:
200x200-myimage1.jpg,
300x300-myimage1.jpg,
200x200-myimage2。 jpg。
I have image files with the name like this:
200x200-myimage1.jpg,
300x300-myimage1.jpg,
200x200-myimage2.jpg.
位置上传/缩略图/线程/
in location uploads/thumbs/thread/
我要删除仅包含名称的文件myimage1.jpg。
I want to delete the file that only contain the name of myimage1.jpg.
我已经使用了像hsz这样的glob来回答:
i have done using glob like hsz answered like this:
$image_name = "myimage1.jpg";
foreach(glob('./uploads/thumbs/thread/'.$image_name) as $rows) {
unlink($rows);
}
但是它不起作用。
but it doesn't work.
Could you help me?
编辑
解决了吗?
i忘记在我的$ image_name之前添加*。
,因此它会变成这样:
glob('./ uploads / thumbs / thread /*'.$ image_name)
推荐答案
要过滤出名称中包含 myimage1
的所有文件,请使用< a href = http://php.net/glob rel = nofollow> glob
To filter out all files that contain myimage1
in the name, use glob
foreach (glob("*myimage1*") as $filename) {
unlink($filename);
}
这篇关于PHP-Codeigniter-如何使用某些名称删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!