8

First off, Mac OS X is not my native operating system but since I'm comfortable in Ubuntu, it's been an easy transition for the most part.

Being that it's Unix-based, I was under the impression this os was case-sensitive, but the file_exists() function is saying otherwise.

In my htdocs file, i have these 2 files:

test.php

MyFiLeWiThMiXeDCaSe.php

In test.php, i have this code:

if(file_exists('myfilewithmixedcase.php')) {
  echo 'exists';
} else {
  echo 'doesnt exist';
}

// ouputs: exists

Anyone know how/why this is happening? This is causing a problem because when we deploy code like this to a linux OS, file_exists() is returning false.

BTW: I'm using MAMP PRO as the local web server.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Mark1inLA
  • 196
  • 1
  • 7
  • 3
    Not an answer to your current question, but it's easy to create a small extra partition that has a case-sensitive file-system and mount that since the default filesystem on osx allows resizing. Put your web projects on that partition to prevent yourself from creating case-sensitivity related bugs/issues. Just watch out with your apache paths if you decide to create a symlink to your new partition. – Simon Groenewolt Apr 05 '13 at 21:38
  • Thank you for the advice, it sounds like if i create a partition for my htdocs folder, it should minimize this issue substantially. – Mark1inLA Apr 05 '13 at 21:45
  • You can write you a case sensitivity version of file_exists() yourself. You can first get the file list of the parent directory,and check if current file is in it with case sensitivity compare. – bronze man Jun 16 '15 at 05:33

3 Answers3

5

Despite being a BSD derivative OS X is NOT case sensitive. Or rather HFs and HFS+ filesystems are not, unless you chose the case sensitive option when formatting your disk. This is usually not done because many applications have issues with this (Adobe, MS, etc.) - or at least they did the last time i tried it under Tiger.

prodigitalson
  • 60,050
  • 10
  • 100
  • 114
3

The default filesystem on OS X is case-insensitive HFS+.

You can format a volume as case-sensitive HFS+, and there are (dirty) ways of enabling case-sensitivity for existing volumes. But, these will break existing software, and you should avoid case-sensitivity on your root volume.

If you need a case-sensitive filesystem for some reason (e.g. building Android requires it), you can make an appropriately-formatted disk image using Disk Utility.

Note that the UNIX foundation of OS X will work just fine with a case-sensitive filesystem.

nneonneo
  • 171,345
  • 36
  • 312
  • 383
  • Thanks for the detailed response. If my disk utility says Format : Mac OS Extended (Journaled), does that mean it's currently case-insensitive? – Mark1inLA Apr 05 '13 at 21:42
  • Yes. Case-sensitive filesystems are specially denoted in Disk Utility. (You can make one easily by creating a new disk image.) – nneonneo Apr 05 '13 at 21:49
1

By default, Mac OS X is not case-sensitive, so "FILE" and "file" are two names for the same file.