【问题标题】:Unable to get the html paths working as desired无法使 html 路径按需要工作
【发布时间】:2018-01-20 16:09:32
【问题描述】:

我正在本地主机上开发我的第一个 PHP webapp。我无法引用我的子目录中的文件。例如,从我项目的任何页面中,如果我必须调用以下页面,则图像不会出现。

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Page is Under Construction</title>
</head>

<body>
<style>
            .imgcontainer {
                text-align: center;
                margin: 10px 0 5px 0;
                position: center;
            }



            </style>

        <div class="imgcontainer" style="padding:0px;">
            <img src="/myProjectRootFolder/images/under-construction.png"  alt=""/>
        </div>

</body>
</html>

控制台上的错误信息是

UnderConstruction.php:25 GET http://localhost/myProjectRootFolder/images/under-construction.png 404 (Not Found)

【问题讨论】:

  • 如果您的页面位于 myProjectRootFolder 下,那么您只需根据图像文件夹的位置调用 。这仅在图像文件夹位于 myProjectRootFolder 中时才有效
  • 在 localhost 中提供子目录和图像位置的完整详细信息

标签: php html directory localhost root


【解决方案1】:

你可能需要一个相对路径

  <img src="./myProjectRootFolder/images/under-construction.png"  alt=""/>

  <img src="./images/under-construction.png"  alt=""/>

并确保您的真实图像和路径名..

如果您调用页面的 url 是

 /myProjectRootFolder/summary/salessummary.php

你应该使用相对路径

<img src="../images/under-construction.png"  alt=""/>

那么你应该使用

【讨论】:

  • 我在 Win 7 x64 上使用 Google Chrome。建议代码也没有给出结果
  • 也是第二个..??
  • /myProjectRootFolder/summary/salessummary.php
  • 即时问题中,underconstruction.php无法定位.png文件
  • 谢谢。
猜你喜欢
  • 1970-01-01
  • 2018-08-22
  • 2014-07-26
  • 1970-01-01
  • 2019-04-19
  • 2021-12-17
  • 1970-01-01
  • 2011-04-02
  • 2015-07-20
相关资源
最近更新 更多