View Full Version : Case Sensitivity

01-09-2004, 09:40 AM

I have a script to check to see if a directory exists on the webserver. I am passing in the folder name and seeing if it exists. If a user types in the correct name for a folder but in the wrong case I would like my code to still return that the directory exists....

here is my code:

$path = 'images'; //works
$folder = 'bananas';
$test = $path.'/'.$folder;

print '<br>Path to Directory = ' . $test;

if (is_dir ($test)) {
print "<br><br>++Dir exists" . '[' . $test .']';
} else {
print "<br><br>--Dir doesn't exist" . '[' . $test .']';

At the moment it will return "Dir doesn't exist' as the folder is named 'Bananas' - I would like it to be case sensitive....

Any ideas on how to achieve this?


01-09-2004, 01:48 PM
nothing straightforward that I can think of ...you could load the files into an array ... if you have >=4.3.0 use glob();

foreach (glob("/home/user/path/*" , GLOB_ONLYDIR ) as $dir) {
if( strtoupper( $dir ) == strtoupper( $search_string ) ){
echo "Found $dir";break;

note that GLOB_ONLYDIR flag seems not to work for me on 4.3.4 on win32 , though on win32 directories and paths should be case-insensitive anyway ??