PHP include_once不显示图片

时间:2013-03-15 05:42:29

标签: php include

我正在使用php构建我的第一个站点。我创建了一个名为'header.php'的文件,其中包含我的导航和图片。在我的'index.php'上,我在div中写入了标题应该放在<?php include_once 'inc/header.php'; ?>现在,你可以看到文件包含但图片没有显示,看起来div样式不是工作是因为图片的占位符在错误的位置。如果你在浏览器中查看'header.php',那么一切看起来都很好,图片上有容器样式。我在这里错过了什么?这是我的header.php文件:

<style type="text/css">
@import url("../site_css/Css_reset.css");
@import url("../site_css/craig-smith.css");
</style>




<div class="picture"><img src="../graphics/header1.gif" />
        <div id="nav">

<table style="display: inline-table;" border="0" cellpadding="0" cellspacing="0" width="400">
  <!-- fwtable fwsrc="navback_temp.png" fwpage="Page 1" fwbase="nav.jpg" fwstyle="Dreamweaver" fwdocid = "1996150392" fwnested="0" -->
  <tr>
    <td><img src="../graphics/nav/spacer.gif" width="80" height="1" border="0" alt="" /></td>
    <td><img src="../graphics/nav/spacer.gif" width="70" height="1" border="0" alt="" /></td>
    <td><img src="../graphics/nav/spacer.gif" width="134" height="1" border="0" alt="" /></td>
    <td><img src="../graphics/nav/spacer.gif" width="116" height="1" border="0" alt="" /></td>
    <td><img src="../graphics/nav/spacer.gif" width="1" height="1" border="0" alt="" /></td>
  </tr>
  <tr>
    <td><a href="javascript:;" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage('nav_r1_c1','','../graphics/nav/nav_r1_c1_s2.jpg',1);"><img name="nav_r1_c1" src="../graphics/nav/nav_r1_c1.jpg" width="80" height="40" border="0" id="nav_r1_c1" alt="" /></a></td>
    <td><a href="javascript:;" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage('nav_r1_c2','','../graphics/nav/nav_r1_c2_s2.jpg',1);"><img name="nav_r1_c2" src="../graphics/nav/nav_r1_c2.jpg" width="70" height="40" border="0" id="nav_r1_c2" alt="" /></a></td>
    <td><a href="javascript:;" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage('nav_r1_c3','','../graphics/nav/nav_r1_c3_s2.jpg',1);"><img name="nav_r1_c3" src="../graphics/nav/nav_r1_c3.jpg" width="134" height="40" border="0" id="nav_r1_c3" alt="" /></a></td>
    <td><a href="javascript:;" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage('nav_r1_c4','','../graphics/nav/nav_r1_c4_s2.jpg',1);"><img name="nav_r1_c4" src="../graphics/nav/nav_r1_c4.jpg" width="116" height="40" border="0" id="nav_r1_c4" alt="" /></a></td>
    <td><img src="../graphics/nav/spacer.gif" width="1" height="40" border="0" alt="" /></td>
  </tr>
</table>
        </div>
    </div>

这是index.php的相关信息

<body>

<div id="body">
    <div id="header">
      <?php include_once 'inc/header.php'; ?>
        </div>

4 个答案:

答案 0 :(得分:0)

试试这个:

<?php include_once './inc/header.php'; ?>

答案 1 :(得分:0)

路径应该相对于index.php而不是header.php。使用Dreamweaver更改header.php需要手动更改路径,因为它会使所有内容都相对于header.php。

答案 2 :(得分:0)

图像路径需要相对于index.php,而不是包含文件。您需要从../路径

中删除<img>

答案 3 :(得分:-1)

您确定路径是否正确?文件层次结构是什么样的?