Reputation: 31
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
Upvotes: 0
Views: 3072
Reputation: 620
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;
}
Upvotes: 1
Reputation: 859
Use strtolower on your filenames to check if they exist.
if(strtolower($filename) === '2323a.png')
Upvotes: 0