• <i id='tzfwk'><tr id='tzfwk'><dt id='tzfwk'><q id='tzfwk'><span id='tzfwk'><b id='tzfwk'><form id='tzfwk'><ins id='tzfwk'></ins><ul id='tzfwk'></ul><sub id='tzfwk'></sub></form><legend id='tzfwk'></legend><bdo id='tzfwk'><pre id='tzfwk'><center id='tzfwk'></center></pre></bdo></b><th id='tzfwk'></th></span></q></dt></tr></i><div id='tzfwk'><tfoot id='tzfwk'></tfoot><dl id='tzfwk'><fieldset id='tzfwk'></fieldset></dl></div>

      <tfoot id='tzfwk'></tfoot>
        • <bdo id='tzfwk'></bdo><ul id='tzfwk'></ul>
      1. <small id='tzfwk'></small><noframes id='tzfwk'>

        <legend id='tzfwk'><style id='tzfwk'><dir id='tzfwk'><q id='tzfwk'></q></dir></style></legend>

      2. PHP XAMPP 服务器 DOCUMENT_ROOT 文件夹结构

        时间:2024-04-12

        <small id='LI15C'></small><noframes id='LI15C'>

        <i id='LI15C'><tr id='LI15C'><dt id='LI15C'><q id='LI15C'><span id='LI15C'><b id='LI15C'><form id='LI15C'><ins id='LI15C'></ins><ul id='LI15C'></ul><sub id='LI15C'></sub></form><legend id='LI15C'></legend><bdo id='LI15C'><pre id='LI15C'><center id='LI15C'></center></pre></bdo></b><th id='LI15C'></th></span></q></dt></tr></i><div id='LI15C'><tfoot id='LI15C'></tfoot><dl id='LI15C'><fieldset id='LI15C'></fieldset></dl></div>
          <bdo id='LI15C'></bdo><ul id='LI15C'></ul>

                <tbody id='LI15C'></tbody>
            • <legend id='LI15C'><style id='LI15C'><dir id='LI15C'><q id='LI15C'></q></dir></style></legend>

                  <tfoot id='LI15C'></tfoot>
                  本文介绍了PHP XAMPP 服务器 DOCUMENT_ROOT 文件夹结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以这是我第一次使用 xampp 创建测试站点.我最初将所有 php 文件放在一个文件夹中,最近才决定组织数据(是的,事后看来,我应该从有组织的文件夹结构开始.)无论如何,我的设置如下:

                  So this is my first time creating a test site with xampp. I originally had all my php files in one folder and just recently decided to organize the data (yes, hindsight i should've started with an organized folder structure.) Anyways, I have my setup like this:

                  " [ ] " 表示它是一个文件夹

                  " [ ] " implies it is a FOLDER

                  安装在我的 C: 驱动器上

                  Installed on my C: drive

                  [xampp]
                  └── [htdocs]
                      └── [QMS]
                          └── [rev3]
                              ├── [css]
                              ├── [js]
                              ├── [DPU]
                              ├── [login]
                              ├── index.php
                              ├── header.php
                              └── config.php
                  

                  在我的config.php"文件中,我尝试定义一个根路径(这可能是错误):

                  In my "config.php" file I tried to define a root path (this may be the error):

                  $path = $_SERVER['DOCUMENT_ROOT'] . "/QMS/rev3/";
                  

                  .

                  然后在我的 header.php 文件中我有:

                  Then in my header.php file I have:

                  <?php
                  require $_SERVER['DOCUMENT_ROOT'] . "/QMS/rev3/config.php";
                  include $_SERVER['DOCUMENT_ROOT'] . "/QMS/rev3/login/session.php";
                  .....
                  ?>
                  
                  HTML - located in the <head> section
                  
                  <link rel='stylesheet' type='text/css' href='<?php echo $path . "css/searchBar.css"; ?>'/>
                  <link rel='stylesheet' type='text/css' href='<?php echo $path . "css/tables/filtergrid.css"; ?>'/>
                  <script type="text/javascript" language="javascript" src='<?php echo $path . "js/jquery.dataTables.js" ?>'></script>
                  <script type="text/javascript" language="javascript" src='<?php echo $path . "js/jquery.loader.js" ?>'></script>
                  
                  ... MANY OTHER scripts and stylesheets.
                  

                  .我的 index.php 是:

                  . My index.php is:

                  require $_SERVER['DOCUMENT_ROOT'] . "/QMS/rev3/header.php";
                  

                  当我在 Chrome 中启动它时 - 我的所有脚本和样式表都出现以下错误(总共 19 个错误):

                  When I launch this in Chrome - I get the following errors for ALL of my scripts and stylesheets (19 errors total):

                  "NOT ALLOWED TO LOAD LOCAL RESOURCE  file///C:/xampp/htdocs/QMS/rev3/ ......etc..."
                  

                  当我的所有文件都在同一个文件夹中并且我没有使用 SERVER['DOCUMENT_ROOT'] 时,我的网站运行良好,但现在我不知道该怎么办......有什么建议吗?

                  My site was working perfectly when all my files were in the same folder and I wasn't using SERVER['DOCUMENT_ROOT'], but now I have no idea what to do...any advice?

                  .

                  推荐答案

                  不允许加载本地资源

                  你在<a><link><script>等标签中使用的url应该是相对的文档根目录,例如:

                  The url you use in <a>, <link>, <script>, etc tags should be relative to the document-root, eg:

                  <link rel="stylesheet" type="text/css" href="/QMS/rev3/css/searchBar.css" />
                  

                  不要将磁盘上的路径url的混淆,它们是两个完全不同的东西:)

                  Don't confuse paths on disk with url's, they're two completely different things :)

                  建议确定根路径

                  我建议不要依赖 $_SERVER['DOCUMENT_ROOT'] 变量,而是像这样确定根文件夹(在 config.php 中):

                  I recommend not to rely on the $_SERVER['DOCUMENT_ROOT'] variable, but determine the root-folder like this (in config.php):

                  define('ROOT_PATH', __DIR__);
                  

                  您将拥有一个名为 ROOT_PATH 的常量,其中将包含 C:xampphtdocsQMS ev3(没有尾随 /).

                  You'll have a constant named ROOT_PATH which will contain C:xampphtdocsQMS ev3 (without a trailing /).

                  现在您可以执行以下操作:

                  Now you can do things like:

                  require ROOT_PATH . '/header.php';
                  

                  ROOT_PATH 中的路径与文档根目录不同.如果您真的想使用文档根目录,请执行此操作(这样 ROOT_PATH 将包含 C:xampphtdocs):

                  The path in ROOT_PATH differs from the document-root. If you really want to use the document-root, do this (so that ROOT_PATH will then contain C:xampphtdocs):

                  define('ROOT_PATH', __DIR__ . '/../..');
                  
                  # ...
                  
                  require ROOT_PATH . '/QMS/rev3/header.php';
                  

                  规范化的绝对路径名

                  使用 Capsule 中提到的 realpath() 可能是明智的(展开所有符号链接和解析对 /.//../ 和额外 / 字符的引用):

                  It might be wise to use realpath() as mentioned by Capsule (expand all symbolic links and resolve references to /./, /../ and extra / characters):

                  $rootPath = __DIR__ . '/../..';  # or just __DIR__
                  $realPath = realpath($rootPath);
                  define('ROOT_PATH', $realPath ?: $rootPath);
                  

                  如果 realpath() 无法解析路径,它将返回 false,这就是为什么要进行一些检查.

                  If realpath() fails to resolve the path it will return false, that's why there's a little check.

                  这篇关于PHP XAMPP 服务器 DOCUMENT_ROOT 文件夹结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Laravel 5.1 找不到路由对象 下一篇:在 XAMPP for Mac Lion 10.8 上安装 Php-intl

                  相关文章

                    <bdo id='Jjmyz'></bdo><ul id='Jjmyz'></ul>

                  <small id='Jjmyz'></small><noframes id='Jjmyz'>

                  <tfoot id='Jjmyz'></tfoot>

                1. <i id='Jjmyz'><tr id='Jjmyz'><dt id='Jjmyz'><q id='Jjmyz'><span id='Jjmyz'><b id='Jjmyz'><form id='Jjmyz'><ins id='Jjmyz'></ins><ul id='Jjmyz'></ul><sub id='Jjmyz'></sub></form><legend id='Jjmyz'></legend><bdo id='Jjmyz'><pre id='Jjmyz'><center id='Jjmyz'></center></pre></bdo></b><th id='Jjmyz'></th></span></q></dt></tr></i><div id='Jjmyz'><tfoot id='Jjmyz'></tfoot><dl id='Jjmyz'><fieldset id='Jjmyz'></fieldset></dl></div>
                    1. <legend id='Jjmyz'><style id='Jjmyz'><dir id='Jjmyz'><q id='Jjmyz'></q></dir></style></legend>