views:

182

answers:

2

I need is_dir() to don't care about if the folder or the argument is upper or lower case, or a mix of upper and lower.

So if the foldername is "My Folder" and I run is_dir("mY FoLdEr") the result should be true.

+5  A: 

That's not up to PHP. That's up to operating system and filesystem that PHP is running on. Windows is case insensitive but every version of Unix/Linux is case sensitive.

Let me put it another way: is_dir() is basically a wrapper to a system call or it will use the results of system calls on file info. Those system calls will either return something or not if, by the rules of that operating system and filesystem, a file is found with the matching name. PHP can't change this so no you can't just make is_dir() be case insensitive on Linux.

The best you can do is get a list of files in the directory and loop through them to test to see if any match a case insensitive comparison to what you're looking for.

Note: you might get multiple hits eg "HOME" and "Home" will both match "home". What would such a function (that you want) do in this case?

Alternatively you can change all your filenames to lowercase and then you can use the lowercase version of your input to find the specified file.

cletus
So there is no way to make `is_dir()` to don't care about this?
Johan
@Johan - there is, but as cletus' note points out, such a function would probably be a bad idea.
Dominic Rodger
A: 

Dirty way could be getting list of all directories in actual dir and compare theirs strtolower()-ed names with desired name

yedpodtrzitko