从文件夹中删除图像 [英] Delete images from a folder

查看:132
本文介绍了从文件夹中删除图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用PHP销毁文件夹中的所有图像,我该怎么做?

I want to to destroy all images within a folder with PHP how can I do this?

推荐答案

foreach(glob('/www/images/*.*') as $file)
    if(is_file($file))
        @unlink($file);

glob()返回与通配符模式匹配的文件列表.

glob() returns a list of file matching a wildcard pattern.

unlink()删除给定的文件名(如果成功则返回).

unlink() deletes the given file name (and returns if it was successful or not).

PHP函数名称前的@强制PHP禁止出现函数错误.

The @ before PHP function names forces PHP to suppress function errors.

通配符取决于您要删除的内容. *.*适用于所有文件,而*.jpg适用于jpg文件.请注意,glob还会返回目录,因此,如果您有一个名为images.jpg的目录,它也会同时返回它,从而导致unlink失败,因为它仅删除文件.

The wildcard depends on what you want to delete. *.* is for all files, while *.jpg is for jpg files. Note that glob also returns directories, so If you have a directory named images.jpg, it will return it as well, thus causing unlink to fail since it deletes files only.

is_file()确保仅尝试删除文件.

is_file() ensures you only attempt to delete files.

这篇关于从文件夹中删除图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆