PHP unlink命令删除多个文件
我正在包含以下文件的目录 (user-images/1/p/
) 上调用 php unlink()
函数:
1.jpg
1-s.jpg
1big.jpg
2.jpg
2-s.jpg
2big.jpg
实际调用本身如下
unlink('user-images/1/p/1big.jpg');
:仅删除 1big.jpg
时,它会删除其中包含 1
的所有文件(1big.jpg
、1-s.jpg
,1.jpg
)。我对此进行了相当多的研究,似乎找不到任何人发布类似的问题。
编辑: 下面是完整的脚本,实际上没有太多内容,看不出有什么会受到影响。我以前也从未见过这个:(
<?PHP
unlink('user-images/1/p/1.jpg');
unlink('user-images/1/p/1-s.jpg');
$uid = '1';
$fileName = '467';
$image = '/friskyfriends/user-images/1/p/1-big.jpg';
$width = 320;
$height = 320;
buildPics();
//buildPics($uid,$fileName,$image,$width,$height);
?>
I am calling the php unlink()
function on a directory (user-images/1/p/
) containing the following files:
1.jpg
1-s.jpg
1big.jpg
2.jpg
2-s.jpg
2big.jpg
The actual call itself is as follows:
unlink('user-images/1/p/1big.jpg');
Instead of just deleting 1big.jpg
, it deletes all files with a 1
in them (1big.jpg
, 1-s.jpg
, 1.jpg
). I've researched this quite a bit and can't seem to find anyone posting with a similar issue.
EDIT:
below is the full script, not much there really, don't see how anything could be affected. I've never seen this before either :(
<?PHP
unlink('user-images/1/p/1.jpg');
unlink('user-images/1/p/1-s.jpg');
$uid = '1';
$fileName = '467';
$image = '/friskyfriends/user-images/1/p/1-big.jpg';
$width = 320;
$height = 320;
buildPics();
//buildPics($uid,$fileName,$image,$width,$height);
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为您正在寻找 GLOB 函数,它允许使用通配符进行删除。
例子
I think you are looking for the GLOB function, which allows delete with wildcards.
example
当运行仅包含
unlink
代码的 php 文件时,它工作得很好。我追踪了其余的包含内容(花了很长时间 :( )并发现了之前编码中的一些问题。仍然不确定为什么会影响静态unlink()
调用。也就是说,这是其他地方的问题在已解决的代码中,我感谢大家为帮助我解决此问题而付出的时间和精力......When running the php file with only the
unlink
code in it, it worked fine. I traced through the rest of my includes (took forever :( ) and found some issues in coding before. Still not sure why that affected a staticunlink()
call. That said, it was an issue elsewhere in the code which has been resolved. I appreciate the time and effort everyone put forth to help me troubleshoot this issue...另一种方法和更明确的解决方案可能是路径
another approach and more definitive solution could be with a path
请为您要删除的图像添加取消链接功能。
Please add the unlink function for which image you want to delete.