【问题标题】:PHP deploying to Linux and WindowsPHP 部署到 Linux 和 Windows
【发布时间】:2021-02-23 16:32:52
【问题描述】:

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

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

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

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

【问题讨论】:

  • 假设 Windows 不再是您应该在news-web.php.net/php.internals/110907上花费精力的平台
  • 它是否有效并满足您的要求?是的?继续前进并专注于为您的代码带来价值的其他事情。
  • 是的,它有效,但我想正确地做到这一点

标签: php linux iis path include


【解决方案1】:

您可以尝试使用 PHP 的预定义常量 DIRECTORY_SEPARATOR,它为您提供特定于操作系统的目录分隔符。 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-05
    • 2016-04-18
    相关资源
    最近更新 更多