问题描述
我正在开发一个关于php的网站,我在我的个人电脑上安装了wamp,我的网站文件位于wamp的www文件夹中。
现在考虑www作为我的根文件夹我有一个模板文件夹在根文件夹和模板文件夹中的header.inc.html文件。当我尝试使用绝对路径 include('/ template / header.inc.html');
在任何其他php文件中包含此header.inc.html文件时我错误无法打开流:没有这样的文件或目录,但当我创建一个简单的HTML链接使用相同的绝对路径它完美并打开文件。下面是我的测试代码
<?php
echo'< a href =/ template / header。 inc.html> headerfile< / A>';
包含('/ template / header.inc.html');
?>
如果我给出完整路径例如 C:/ wamp / www /
我很困惑这个问题发生在我的wamp服务器上它可以在任何虚拟主机服务器上正常工作,或者在虚拟主机上也可能存在同样的问题。
我希望有任何帮助可以澄清我的困惑,谢谢。服务器上的绝对路径从服务器的硬盘启动( C:\ $ c $> c $)。
客户端上的绝对路径从网站的根目录开始( http://example.com/
)。
I am developing a website on php, I have installed wamp on my personal computer and my website files are in the www folder of wamp.now considering www as my root folder i have a template folder in the root folder and header.inc.html file in the template folder. when I try to include this header.inc.html file in any other php file using an absolute path include('/template/header.inc.html');
it gives me error "Failed to open stream: No such file or directory", but when I create a simple html link using the same absolute path it perfectly and opens the file. below is my test code
<?php
echo '<a href="/template/header.inc.html">headerfile</a>';
include('/template/header.inc.html');
?>
if I give the full path for example C:/wamp/www/template/header.inc.html
to the include function it works fine.
I am confused that this problem is occurring on my wamp server only and it would work perfectly on any webhost server, or maybe the same problem will exist on a webhost
I would appreciate any help that would clarify my confusion, Thanks.
Absolute paths on the server start from the server's hard disk (C:\
).
Absolute paths on the client start from the root of the website (http://example.com/
).
这篇关于html和php的绝对路径有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!