文档根PHP [英] Document Root PHP

查看:81
本文介绍了文档根PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

  $ _ SERVER [DOCUMENT_ROOT] 



$ b

例如。如果当前文档是:

 文件夹/文件夹/文件夹/ index.php 

我可以使用(在HTML中)从roort开始:

  /somedoc.html 

并且在PHP中执行相同的操作我将不得不使用:

  $ _ SERVER [DOCUMENT_ROOT]。 /somedoc.html; 

这是正确的吗?有没有更简单的方法来做到这一点?

;?php echo $ _SERVER ['DOCUMENT_ROOT']。'/ hello.html';?>> go with php< / a>
< br />
< a href =/ hello.html>转至html< / a>

亲自尝试一下,发现它们不完全一样。



$ _ SERVER ['DOCUMENT_ROOT']呈现一个实际的FILE PATH(在我的计算机上运行,​​因为它是自己的服务器,c:/ wamp / www /



HTML的/呈现服务器url的根,在我的情况下,本地主机/



但c:/wamp/www/hello.html和localhost / hello.html是实际上是同一个文件


Just to confirm, is using:

$_SERVER["DOCUMENT_ROOT"]

the same as using: /

in HTML.

Eg. If current document is:

folder/folder/folder/index.php

I could use (in HTML) to start at the roort:

/somedoc.html

and to do the same in PHP I would have to use:

$_SERVER["DOCUMENT_ROOT"] . "/somedoc.html";

Is that correct? Is there an easier way to do it?

解决方案

 <a href="<?php echo $_SERVER['DOCUMENT_ROOT'].'/hello.html'; ?>">go with php</a>
<br />
<a href="/hello.html">go to with html</a>

Try this yourself and find that they are not exactly the same.

$_SERVER['DOCUMENT_ROOT'] renders an actual FILE PATH (on my computer running as it's own server, c:/wamp/www/

HTML's / renders the root of the server url, in my case, localhost/

But c:/wamp/www/hello.html and localhost/hello.html are in fact the same file

这篇关于文档根PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆