检查php文件夹中是否存在文件

发布于 2024-09-18 09:04:03 字数 199 浏览 3 评论 0原文

我想知道如何在某些条件下检查文件夹中的文件名。

例如 : 文件夹名称是“输出” 该文件夹包含以下图像。 2323a.Png 5235v.Jpeg 2323s.jpg 23523s.JPEG 等等...,

如果我检查文件名是“2323a.png”,但有文件名是2323a.Png。

如何检查文件名是否区分大小写。

提前致谢

i want to know how to check the filename in folder with some condition.

for example :
the folder name is "output"
this folder containing the following the images.
2323a.Png
5235v.Jpeg
2323s.jpg
23523s.JPEG
etc..,

if i check the file name is "2323a.png" but there is file name is 2323a.Png.

how to i check the filename is incasesensitive.

thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撩心不撩汉 2024-09-25 09:04:03

恕我直言,你必须阅读目录内容

function file_exists_ignore_case($path) {
    $dirname = dirname($path);
    $filename = basename($path);
    $dir = dir($dirname);
    while (($file = $dir->read()) !== false) {
        if (strtolower($file) == strtolower($filename)) {
            $dir->close();
            return true;
        }
    }
    $dir->close();
    return false;
} 

Imho you have to read the directory contents

function file_exists_ignore_case($path) {
    $dirname = dirname($path);
    $filename = basename($path);
    $dir = dir($dirname);
    while (($file = $dir->read()) !== false) {
        if (strtolower($file) == strtolower($filename)) {
            $dir->close();
            return true;
        }
    }
    $dir->close();
    return false;
} 
天赋异禀 2024-09-25 09:04:03

在文件名上使用 strtolower 检查它们是否存在。

if(strtolower($filename) === '2323a.png')

Use strtolower on your filenames to check if they exist.

if(strtolower($filename) === '2323a.png')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文