如何使用 WAMP 服务器在网站中包含项目路径
How to include project path in website using WAMP Server
我正在尝试在我的 wampserver 中设置本地网站。
但是,我遇到了一个需要帮助的问题。
尝试从 index.php 访问另一个页面时出现错误。
'Warning: include(localhost/main_project/includes/contants.php):
failed to open stream: No such file or directory in
C:\wamp64\www\main_project\index.php on line 55'.
但是,我在包含文件夹中看到了我的文件 constants.php。这就是我在 index.php
中设置路径的方式
$project_path = 'localhost/main_project/';
我用这个变量去引用constants.php
include $project_path . 'includes/constants.php';
请让我知道我应该做什么。
谢谢!
你无法完成你想要完成的事情。 include
和require
中指定的路径只能是相对路径。如果你想给它添加一个基本变量,你可以这样做:
$relativePath = $_SERVER['DOCUMENT_ROOT'];
include $relativePath.'/includes/contants.php';
我正在尝试在我的 wampserver 中设置本地网站。
但是,我遇到了一个需要帮助的问题。
尝试从 index.php 访问另一个页面时出现错误。
'Warning: include(localhost/main_project/includes/contants.php): failed to open stream: No such file or directory in C:\wamp64\www\main_project\index.php on line 55'.
但是,我在包含文件夹中看到了我的文件 constants.php。这就是我在 index.php
中设置路径的方式$project_path = 'localhost/main_project/';
我用这个变量去引用constants.php
include $project_path . 'includes/constants.php';
请让我知道我应该做什么。
谢谢!
你无法完成你想要完成的事情。 include
和require
中指定的路径只能是相对路径。如果你想给它添加一个基本变量,你可以这样做:
$relativePath = $_SERVER['DOCUMENT_ROOT'];
include $relativePath.'/includes/contants.php';