gpt4 book ai didi

php 通过使用 ..(双点)引用包含路径

转载 作者:太空宇宙 更新时间:2023-11-04 04:35:10 25 4
gpt4 key购买 nike

我有一个关于 PHP 包含路径的问题,它在两个环境中的行为不同。

文件夹结构:

Windows

|-C:\wamp\www\cms\themes\child
|-C:\wamp\www\cms\themes\parent

Linux

|-/var/www/html/cms/themes/child
|-/var/www/html/cms/themes/parent

Linux环境

var_dump(realpath('/')); // means /
var_dump(realpath('/../parent/scripts/import.php')); //boolean false
include('/../parent/scripts/import.php'); //it will not work
include('../parent/scripts/import.php'); //it will not work, except it will reference parent folder

Windows环境

var_dump(realpath('/')); //C:\
var_dump(realpath('/../parent/scripts/import.php')); //boolean false
include('../parent/scripts/import.php'); //am thinking it will work at first, but it does not work in windows (feel weird)
include('/../parent/scripts/import.php'); //it work in windows (feel weird)

我知道最好的做法是,它在两个平台上都有效

include(realpath(dirname(__FILE__)).'/../parent/scripts/import.php');

但是我想知道这是一个 PHP 错误还是什么原因导致的?

最佳答案

不,这不是一个错误,而是 Windows 文件系统和 Linux 文件系统之间的差异

关于php 通过使用 ..(双点)引用包含路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14620849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com