PHP7.4绝对路径-为什么是/。。忽略?
我用它来包含一些文件PHP7.4绝对路径-为什么是/。。忽略?,php,php-7.4,Php,Php 7.4,我用它来包含一些文件 require_once realpath(__DIR__) . '/../anotherfolder2/anotherfolder3/filename2.php 但出于某些原因,似乎是/。。被忽略并触发 无法打开必需的“/var/domains/domain.com/foldername1/anotherfolder2/anotherfolder3/filename.php” 在第10行的/var/domains/domain.com/foldername1/anoth
require_once realpath(__DIR__) . '/../anotherfolder2/anotherfolder3/filename2.php
但出于某些原因,似乎是/。。被忽略并触发
无法打开必需的“/var/domains/domain.com/foldername1/anotherfolder2/anotherfolder3/filename.php”
在第10行的/var/domains/domain.com/foldername1/anotherfolder2/filename1.php中`
其中realpath(DIR)=/var/domains/domain.com/foldername1
什么可能导致/。。要忽略的是,这是PHP7.4中的新功能吗?尝试将整个路径传递给realpath()函数:
require\u once realpath(\uuuu DIR\uuuu.'/../anotherfolder2/anotherfolder3/filename2.php)
此函数将dir1/dir2/./file1
更改为dir1/file1
。
在您的例子中:/var/domains/domain.com/foldername1/./anotherfolder2/anotherfolder3/filename.php
转换为/var/domains/domain.com/anotherfolder2/anotherfolder3/filename.php
从文件:
realpath()展开所有符号链接,解析对输入路径中/、/../和额外/字符的引用,并返回规范化的绝对路径名
尝试将整个路径传递给realpath()函数:
require\u once realpath(\uuuu DIR\uuuu.'/../anotherfolder2/anotherfolder3/filename2.php)
此函数将dir1/dir2/./file1
更改为dir1/file1
。
在您的例子中:/var/domains/domain.com/foldername1/./anotherfolder2/anotherfolder3/filename.php
转换为/var/domains/domain.com/anotherfolder2/anotherfolder3/filename.php
从文件:
realpath()展开所有符号链接,解析对输入路径中/、/../和额外/字符的引用,并返回规范化的绝对路径名
我相信你说的
realpath(\uuuu DIR\uuuu)
是'/var/domains/domain.com/foldername1'
是不正确的
错误消息包括发生错误的文件路径:
。。。在第10行的/var/domains/domain.com/foldername1/anotherfolder2/filename1.php中
所以我们知道,\uuuuuuuuuuuuuuuuuuuu
将是'/var/domains/domain.com/foldername1/anotherfolder2/filename1.php'
,而\uuuuuu DIR\uuuuuuuuu
将是'/var/domains/domain.com/foldername1/anotherfolder2'
realpath
不太可能改变这一点,因此我们有:
require_once '/var/domains/domain.com/foldername1/anotherfolder2' . '/../anotherfolder2/anotherfolder3/filename2.php'
。
将去掉第一个另一个文件夹2
给出:
require_once '/var/domains/domain.com/foldername1/anotherfolder2/anotherfolder3/filename2.php'
错误消息说找不到的是哪个文件路径。我相信您关于
realpath(\uuuu DIR\uuuu)
是'/var/domains/domain.com/foldername1'
的说法是不正确的
错误消息包括发生错误的文件路径:
。。。在第10行的/var/domains/domain.com/foldername1/anotherfolder2/filename1.php中
所以我们知道,\uuuuuuuuuuuuuuuuuuuu
将是'/var/domains/domain.com/foldername1/anotherfolder2/filename1.php'
,而\uuuuuu DIR\uuuuuuuuu
将是'/var/domains/domain.com/foldername1/anotherfolder2'
realpath
不太可能改变这一点,因此我们有:
require_once '/var/domains/domain.com/foldername1/anotherfolder2' . '/../anotherfolder2/anotherfolder3/filename2.php'
。
将去掉第一个另一个文件夹2
给出:
require_once '/var/domains/domain.com/foldername1/anotherfolder2/anotherfolder3/filename2.php'
错误消息说找不到的是哪个文件路径。日志中是否有其他与此相关的错误消息?首先执行
realpath(\uuu DIR\uuu)
有什么意义<代码>\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu/另一个文件夹2/…。日志中是否有其他与此相关的错误消息?首先执行realpath(\uuu DIR\uuu)
有什么意义<代码>\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu/另一个folder2/…realpath()
,虽然在这里是多余的,但既不是问题,也不是解决方案。它只是得到了一条规范路径。它不会更改它指向的位置。realpath()
,虽然在这里是多余的,但这既不是问题,也不是解决方案。它只是得到了一条规范路径。它不会改变它指向的位置。