我正在使用 WAMP 在本地构建一个 PHP mySQL 站点。
在我的 WAMP www 目录中,我为我正在制作的每个网站制作了子文件夹。例如:
WAMP\www\site1\index.php
WAMP\www\site2\index.php
WAMP\www\site3\index.php
etc
我的数据库连接存储在:
site1/connections/open.php
我的 PHP 脚本存储在:
site1/php/filename.php
当我运行脚本时,我需要包含 open.php 连接。我能让它工作的唯一方法是使用:
include '../connections/open.php'; // this goes at the top of the PHP script
我知道,如果我使用它然后移动到远程服务器或四处移动一些目录,我将无法访问该文件。因此,我希望路径相对于 basedir 或 baseurl(/site1/)。
我知道当您使用 include 时,它正在寻找一个目录而不是一个 url,所以我不能使用类似的东西;
$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
您如何解决这个问题?谢谢
最佳答案
是的,您在 URL 部分是正确的
I understand that when you use an include it is looking for a dir and not an url so I cant use anything like;
$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
How do you go about sorting this out? Thanks
你应该这样尝试
$_SERVER["DOCUMENT_ROOT"]."/myFolder/"
或者试试这个
getcwd()."/myFolder/"
但两者之间存在差异[尝试谷歌搜索]
关于php - 基本 Url PHP 包含在 WAMP 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22410959/