【问题标题】:Images not appearing in hostgator (cPanel) but appearing in localhost图像未出现在 hostgator (cPanel) 中但出现在 localhost
【发布时间】:2021-07-27 00:47:39
【问题描述】:

由于某种原因,当我在 hostgator 索引文件(public_html 下)中引用 CSS 文件或图像文件时,它们不起作用,但当我在本地测试时它就起作用了。这是我尝试使用通过 cPanel 上传到 public_html 文件夹的图像的示例:

<!DOCTYPE html>
<html>

<head>
<title>mydomain.com</title>
</head>

<h1>Here is an image</h1>
<img src="public_html/me.JPG" alt="pic of me">
<p style="background-color:#ECEBE9;">Here is more text

</p> 
</body>
</html>

我试过了:

  • 更改权限(public_html 中的所有内容都是 755 和 public_html 是 750 as per hostgator's instructions)
  • 使用完整路径:“/home/username/public_html/”(使用我的用户名并尝试使用“home3”而不是“home”)
  • 将 JPG 放入名为 images 的子文件夹中并使用该路径名

我假设路径很明显,但我真的不明白为什么 index.html 文件无法访问 hostgator 上同一文件夹中的 CSS 或图像文件,所以请让我知道还有什么可以尝试的.

【问题讨论】:

    标签: html css path localhost cpanel


    【解决方案1】:
    <img src="public_html/me.JPG" alt="pic of me">
    
    1. 你能把public_html用唯一的me.JPG吗?
    2. 请检查图片扩展名是 .JPG 还是 .jpg?

    【讨论】:

    • 它实际上是 .JPG,我尝试将我的代码行换成你的,我得到了相同的结果。
    • 你能检查你的代码.jpg是大写吗?
    【解决方案2】:

    如果 me.JPG 与 html 文档位于同一文件夹中,请使用 src="me.JPG"

    使用相对路径而不是绝对路径。

    【讨论】:

    • 出于某种原因,这行得通!知道为什么绝对路径不起作用吗?
    猜你喜欢
    • 2017-09-29
    • 2015-04-07
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    • 1970-01-01
    相关资源
    最近更新 更多