我在理解相对路径概念方面面临困难,我看到了代码的一部分,如
../../abc/file/images/picutre/down.gif如何计算相对路径
发布于 2015-02-24 08:08:27
相对路径是相对于工作目录的路径。换句话说,查找文件的起点是工作目录。
相对路径中的"../“意味着上升一个目录。
因此,假设您在以下结构中引用来自index.html页面的相对路径index.html:
http://someexampleurl.com/dir1/dir2/index.html在index.html工作时,您的工作目录是/dir2,因此考虑到您要上升两个级别,浏览器希望该文件位于:
http://someexampleurl.com/abc/file/images/picutre/down.gif发布于 2015-02-24 07:56:50
如何计算相对路径
基本上,相对路径是从您所在的目录到您需要包含的文件的“映射”。因此,相对路径是根据您想要去的位置计算的。
例如,您有一个结构
/ (document root)
|--home.php
|--t.php
|--common
|--header.php
|--footer.php
|--support
|--index1.php
|--privacy
| |--index2.php在home.php中,您需要包含header和footer。因此,您的家庭代码看起来就像
<?php
include("common/header.php"); // go one folder down (common) and grab the file header.php
include("common/footer.php"); // go one folder down (common) and grab the file footer.php现在假设您支持index1.php,并且需要header.php和footer.php。你的代码看起来就像
<?php
include("../common/header.php"); // go one folder up (common) and grab the file header.php
include("../common/footer.php"); // go one folder up (common) and grab the file footer.php将文件夹中的文件夹视为级别(level1、level2等)
注意:要小心相对路径,这是一种痛苦。
发布于 2015-02-24 07:27:43
它说从当前位置返回两个级别(父目录)“.././”。
https://stackoverflow.com/questions/28690228
复制相似问题