简体   繁体   English

在PHP中加载图像文件的问题

[英]Issue in loading image file in PHP

I am facing some typical issue in loading image files in PHP. 我在用PHP加载图像文件时遇到一些典型的问题。 Image got successfully loaded but cannot get displayed properly. 图像已成功加载,但无法正确显示。

I have declared a define value, then echoed it in an img tag src attribute : 我已经声明了一个定义值,然后在img标签src属性中回显了它:

define('image_site_url','localhost/projects/faantush/product_images/');
<img src="<?php echo image_site_url.$row['image1'] ?>" />

The image file is not found but it is there in product_images. 找不到图像文件,但它在product_images中。 Here are the pictures: 这是图片:

浏览器检查器中DOM的屏幕截图 屏幕截图证明了图像已正确投放

In the HTML code: You are missing the: http:// before localhost 在HTML代码中:您缺少: localhost之前的http://

<img src="http://localhost/ ... <img src="http://localhost/ ...

If your pictures are hosted on the same server than your website, you don't really need to use an absolute path. 如果您的图片与网站托管在同一台服务器上,那么您实际上不需要使用绝对路径。 You could use a relative path and remove the domain name ( localhost in this case): 您可以使用相对路径并删除域名(在这种情况下为localhost ):

<img src="/projects/path/to/your/picture.jpg" />

You must use absolute paths when linking to another website, but you can also use absolute paths within your own website. 链接到另一个网站时,必须使用绝对路径,但也可以在自己的网站中使用绝对路径。 This practice is generally frowned upon, though. 但是,这种做法通常不被接受。 Relative links make it easy to do things like change your domain name without having to go through all your HTML pages, hunting down links and changing the names. 相对链接使您可以轻松完成诸如更改域名之类的操作,而无需浏览所有HTML页面,查找链接和更改名称。 As an added bonus, they force you to keep your site structure neat and organized, which is always a good idea. 另外,它们会迫使您保持网站结构整洁有序,这始终是一个好主意。

An interesting use case of not using absolute paths is, if you want to set your website to SSL/TLS : you will have to change all the occurrences of http to https . 一个不使用绝对路径的有趣用例是,如果要将网站设置为SSL/TLS ,则必须将所有出现的http都更改为https Although it is not a big deal, this is generally not the kind of work you want to do. 尽管这没什么大不了,但这通常不是您想要执行的工作。

See Relative path or url for html src and href attributes and the post from where this quote is taken . 有关html src和href属性的详细信息,请参见相对路径或url,以及 引用该引用的位置帖子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM