case sensitivity on Mac for file_exists()?

2019-02-17 00:54发布

问题:

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.

回答1:

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.



回答2:

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.



回答3:

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