-2

如何定义$docroot路径以便输入自己的路径。

我有代码:

$docroot = getenv("DOCUMENT_ROOT");

当我将它与我的 index.php 结合使用时:

索引.php

$docroot = getenv("DOCUMENT_ROOT");
require_once("access/$template/head.php");  

并且在 required_once 链接文档head.php上有以下代码:

头文件

<link rel='stylesheet' href='$docroot/$template/css/style.css'>

上面的代码使:

/home/users/web/b192/dom.icorporationus/public_html/blanky-store.net/models/site-templates/rd-web_design-black_colours/css/style.css

这是添加的代码

/home/users/web/b192/dom.icorporationus/public_html/blanky-store.net/

如何更改我$docroot的,而不是显示我的服务器的完整路径,而是显示路径:

/access/
4

1 回答 1

-1

You don't need to add the $docroot variable to your HTML code at all, since that's the path the server uses. Your template shouldn't reference it.

If this is some code you'd rather not touch, here's how to override it (at the risk of breaking a lot of other code):

putenv('DORUMENT_ROOT=');
$docroot='';

Of course you need to run it in front of your index.php code.

Now a piece of advice:

  1. To access static resources, use a helper function to get the full path. (like get_static('/path/to/resource'). This makes it easier to relocate your static resources.
  2. This way of organizing your pages is horribly outdated and should not be practiced any more. Consider reading up on modern day PHP applications. (Article by me.)
于 2013-07-07T21:15:49.517 回答