将变量设置为当前目录

Set variable to current directory

我正在尝试将变量设置为当前工作目录。我使用了下面的代码:

$docs_uri = getcwd() . "/head_tag.php";

但是当我尝试将路径放在如下锚标记中时:

echo "<a href='$docs_uri'>TEST</a>";

即使它位于那里。因为当我从 url 中删除 PROJECT-GMPU 之前的所有内容时,比如 '/applications/MAMP/htdocs/' 我得到了文件。

我收到这个错误:

The requested URL /Applications/MAMP/htdocs/PROJECT-GMPU/data-information-knowledge/javascript-documentation/head_tag.php was not found on this server.

getcwd() 将 return 你的物理路径。它不会 return 你的网络路径。 URL /Applications/MAMP/htdocs/PROJECT-GMPU/data-information-knowledge/javascript-documentation/head_tag.php

将呈现为 http://localhost/Applications/MAMP/htdocs/PROJECT-GMPU/data-information-knowledge/javascript-documentation/head_tag.php

我认为这不是应用程序的路径。您可以使用以下代码来确定路径:

$currentWebDir = substr(__DIR__, strlen($_SERVER['DOCUMENT_ROOT']));