【问题标题】:dynamic url path from current file in changing directories with php使用php更改目录中当前文件的动态url路径
【发布时间】:2016-01-10 23:26:09
【问题描述】:

我需要包含来自不同目录和文件路径结构的相同文件 (navigation.php)。 例如,我需要动态更改文件深度,例如:

include '../../../navigation.php';

include '../../../../../navigation.php';

需要是同一个文件(navigation.php)。

此外,我需要将 (navigation.php) 的 css 和 javascript 文件的绝对路径存储在一个变量中,该变量在我网站的所有目录中都相同,如前所述。 例如,在以下情况为真时:

<link rel="stylesheet" href="../css/main.css">  

<link rel="stylesheet" href="../../../css/main.css">

两个目录路径都需要被一个像这样的变量引用

  <link rel="stylesheet" href="<?php echo $rootpath; ?>/css/main.css">

我尝试过使用&lt;?php echo " ".realpath($_SERVER["DOCUMENT_ROOT"])."/path/to/root/"

但是这似乎不起作用,因为我最终得到了一条看起来像这样的路径

C:\before\root/path/to/root.

制作标准动态变量的最有效方法是什么,该变量将指示相对于当前文件夹的路径,或者我如何解决我在使用绝对路径时遇到的当前问题?

【问题讨论】:

    标签: php dynamic include absolute directory-structure


    【解决方案1】:

    我尝试使用 basename 函数? http://php.net/manual/en/function.basename.php ?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-04
      • 2011-10-21
      • 2019-05-10
      • 1970-01-01
      • 2014-05-24
      相关资源
      最近更新 更多