html和php中的绝对路径有什么区别? [英] what is the difference of absolute path in html and php?

查看:19
本文介绍了html和php中的绝对路径有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用php开发一个网站,我在我的个人电脑上安装了wamp,我的网站文件在wamp的www文件夹中.现在考虑将 www 作为我的根文件夹,我在根文件夹中有一个模板文件夹,在模板文件夹中有 header.inc.html 文件.当我尝试使用绝对路径将这个 header.inc.html 文件包含在任何其他 php 文件中时 include('/template/header.inc.html'); 它给了我错误Failed to打开流:没有这样的文件或目录",但是当我使用相同的绝对路径创建一个简单的 html 链接时,它可以完美运行并打开文件.下面是我的测试代码

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 works 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');
?>

如果我给包含函数的完整路径例如 C:/wamp/www/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.

我很困惑这个问题只发生在我的 wamp 服务器上,它可以在任何虚拟主机服务器上完美运行,或者同样的问题可能会存在于虚拟主机上

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.

推荐答案

服务器上的绝对路径从服务器的硬盘 (C:) 开始.
客户端上的绝对路径从网站的根目录 (http://example.com/) 开始.

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中的绝对路径有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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