Mac / MAMP 上 PHP 文件路径大小写不一致?
我正在 MAMP 上开发 PHP 程序,刚刚意识到以下奇怪的行为:
echo "<br/>PATH = ".dirname(__FILE__);
include 'include.php';
include.php:
<?php
echo "<br/>PATH = ".dirname(__FILE__);
?>
结果:
PATH = /users/me/stuff/mamp_server/my_site(全部小写)
PATH = /Users/me/Stuff/mamp_server/my_site(混合大小写)
是什么导致了这种不一致的行为,以及如何防止这种情况发生? (请注意,我不能将所有内容都转换为小写,因为该应用程序是针对 Linux 服务器的,其中文件路径区分大小写。)
更新:
__FILE__和<代码>__DIR__。
看起来这可能是一个真正的问题,没有解决办法......除非我听到其他消息,否则我将提交错误报告。
错误报告:
https://bugs.php.net/bug .php?id=60017
更新:
另请注意:如果您在 Mac 上执行绝对路径 include(...),则需要混合大小写版本。
I'm developing a PHP program on MAMP, and just realized the following screwy behavior:
echo "<br/>PATH = ".dirname(__FILE__);
include 'include.php';
include.php:
<?php
echo "<br/>PATH = ".dirname(__FILE__);
?>
Result:
PATH = /users/me/stuff/mamp_server/my_site (All lower case)
PATH = /Users/me/Stuff/mamp_server/my_site (Mixed case)
What is causing this inconsistent behavior, and how can I protect against it? (Note that I can't just convert everything to lowercase, because the application is destined for a Linux server, where file paths are case sensitive. )
Update:
This problem exists for __FILE__
and __DIR__
.
It looks like this might be a real problem with no work around... going to file a bug report unless I hear otherwise.
Bug report:
https://bugs.php.net/bug.php?id=60017
Update:
And another note: If you're doing an absolute path include(...) on Mac, it requires the mixed case version.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我在 MAC OS X 上开发 PHP 时遇到了类似的问题。您可以使用区分大小写的文件系统进行格式化,但如果您使用 Adobe 的设计软件,您可能会遇到麻烦:http://forums.adobe.com/thread/392791
真正的问题是,据说不区分大小写的文件系统实际上是部分不区分大小写的。您可以在同一目录中创建两个名为“Filename”和“filename”的文件,但“Filename”和“filename”可能指向这两个文件: http://systemsboy.com/2005/12/mac-osx-command-line-is-partially-case-insensitive.html
I have had similar problems developing PHP on MAC OS X. You can format with a case sensitive filesystem but if you are using Adobe's design software you might run into trouble: http://forums.adobe.com/thread/392791
The real issue is that the file system that is said to be case insensitive is in actual fact partially case insensitive. You can create two files with names 'Filename' and 'filename' in the same directory but 'Filename' and 'filename' may point to both files: http://systemsboy.com/2005/12/mac-osx-command-line-is-partially-case-insensitive.html
在与您的应用程序相同的目录中创建一个包含文件怎么样?
像这样使用它:
从您上面发布的内容来看,这应该可行。是的,这是一个有点棘手的解决方法,但它是一种解决方法,即使在没有遇到此问题的系统上也应该有效。
What about creating an include file in the same directory as your app.
Use it like so:
From what you posted above, this should work. Yes, it's a bit of a hacky workaround, but it is a workaround, and should work even on systems not suffering from this issue.
这是我用来获取给定文件名的正确大小写的代码:
glob 应该只匹配一个文件,但如果在区分大小写的文件系统上使用,那么它可以匹配更多文件 - 所需的行为取决于您 - 例如返回 < code>[0] 无论如何,或者抛出一个
E_NOTICE
或其他东西。您可能会发现它很有帮助:
$mydir = get_cased_filename(dirname(__FILE__));
适用于 Mac 10.6.8 上的 CLI PHP 5.3.6。我用它来处理那些没有注意到“文件名”和“文件名”不同的同事。 (这些人还想知道为什么包含“>”或“?”的文件名在从 Mac 复制到 Windows 服务器时不起作用,但我离题了......)
This is the code I use to get the correct casing of a given filename:
The glob should only match one file, but if used on a case sensitive file system then it could match more - required behaviour is up to you - eg return the
[0]
anyway or throw aE_NOTICE
or something.You might find it helpful:
$mydir = get_cased_filename(dirname(__FILE__));
Works for my CLI PHP 5.3.6 on Mac 10.6.8.I use it to deal with coworkers who don't notice things like "Filename" and "filename" being different. (These people also wonder why filenames that contain ">" or "?" don't work when copying from Mac to Windows server, but I digress...)
我正在使用 apache,我发现执行文件的 __DIR__ 与 apache 配置的 DOCUMENT_ROOT 中找到的文件相同。
这意味着如果 apache 配置有
问题中的脚本正在打印:
如果 apache 配置有:
问题中的脚本正在打印:
哪个更好。
如果遇到此问题,请检查 apache 配置,并考虑到它区分大小写。
I was using apache and I found that the
__DIR__
of the executed file was the same one found in the DOCUMENT_ROOT of the apache config.That means that if the apache config had
script from the question was printing:
And if the apache config had:
script from the question was printing:
Which was much better.
If you encounter this problem, check the apache configuration taking into account that it's case sensitive.