PHP realpath on Windows Case Issue

故事扮演 提交于 2019-12-06 09:09:11

Turns out

do {
    $to = realpath($to);
} while (realpath($to) !== false && $to !== realpath($to));

is the only way.

https://bugs.php.net/bug.php?id=61933

This makes sense, if you think it through. For the first path resolution, it is finding what was defined as the link target. For the second, you end up with the same path, but one with the proper upper-case for the drive letter.

Under Windows file systems, paths/file names are case insensitive. To compare them, just convert both to upper or lower case before testing.

if (strtoupper(realpath($to)) !== strtotupper(realpath($from))) {
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!