tags:

views:

35

answers:

2

hi

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

A: 

Use strtolower on your filenames to check if they exist.

if(strtolower($filename) === '2323a.png')
Leon
if i check the file name is 2323a.pNg, then what will i do?
hussain
Add a str_replace around the strtolower() function, str_replace('.png', '.pNg', strtolower($filename)). But if you lowercase the filenames this shouldn't be needed because everything will be lowercase.
Leon
+1  A: 

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