0

index.php我在根文件夹中有一个站点,其中/img的图像overview.php位于/content. 我有一个sidebar.php包含在index.php和中的文件overview.php/img/image.gif如果我在每个文件中都包含一个链接,我应该如何引用?相对于引用它的文件
位置的更改位置。 使用in将在 中工作,但对于位于 的文件则失败。 我能看到的唯一解决方案是在每个子目录中包含一个单独的目录,或者在每个子目录中包含一个目录。 我能找到的最佳建议是按照此处的建议使用 > HTML 标记:image.gif
/img/image.gifsidebar.phpindex.php/content/overview.php
sidebar.php/img
<base
更改 PHP 中包含内容的相对链接路径

但是,在同一个链接中,SamGoody 建议<base> 标签is no longer properly supported in Internet Explorer, since version 7.

在采取行动之前,我想对此事有一些了解。

谢谢。

编辑:我在下面使用了错误的方法"../"

例子-

根/index.php:

...  
<link rel="stylesheet" type="text/css" href="style.css" />  
<title>title</title>  
</head>  
<body>  
<?php include('include/header.php'); ?>  
<?php include('include/menu.php'); ?>
...  

根/包含/header.php:

...  
<div id="header">  
<span class="fl"><img src="img/dun1.png"/></span><span class="fr"><img src="img/dun2.png"/></span> 
...  

根/内容/overview.php:

...  
<link rel="stylesheet" type="text/css" href="../style.css" media="screen" />  
<title>Overview</title>  
</head>  
<body>  
<?php include('../include/header.php'); ?>
<?php include('../include/menu.php'); ?>
...
4

1 回答 1

3

在 sidebar.php 中使用 /img/image.gif 可以在 index.php 中使用,但对于位于 /content/overview.php 的文件会失败

但它不应该。前面/使它成为一个绝对路径,可以从服务器上的任何点开始工作。如果这对您不起作用,则说明某处存在问题-在这种情况下,请发布一些示例。

Unless you are planning to move the whole site into a sub-directory one day, or move images to a Content Delivery Network (both actions would require re-writing the addresses) you can safely use absolute URLs.

于 2011-01-14T11:45:46.917 回答