开发者

check file exists or not in folder in php

i want to know how to check the filename i开发者_StackOverflow中文版n 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


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;
} 


Use strtolower on your filenames to check if they exist.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜