PHP 部署到 Linux 和 Windows

PHP deploying to Linux and Windows

根据我是将我的网站部署到 Linux 还是 Windows,我设置我的包含路径如下:-

if(PHP_OS==="WINNT")
    include("..\library\chopper.inc");
else 
    include("/home/site/wwwroot/library/chopper.inc");

我确定这不是最好的方法!

根据环境设置路径的正确方法是什么?

您可以尝试使用 PHP 的预定义常量 DIRECTORY_SEPARATOR,它会为您提供 OS 特定的目录分隔符。 DIRECTORY_SEPARATOR 分隔路径内的目录: In Windows '' In other systems'/'

https://www.php.net/manual/en/dir.constants.php

https://www.php.net/manual/en/function.set-include-path.php