简体   繁体   中英

HTML img tag not working

I'm trying to display some images on a website, but for some reasons, they are not showing up. This is the code I'm using, which is similar to what I found on the internet, but it just prints Error. How can I fix this?

<?php

echo '<img src="D:/website/images/pic.jpg" alt="Error" />';

?>

是的,它不起作用,您应该使用服务器URL来代替D:/website/images/pic.jpg是系统路径

 echo '<img src="http://example.com/website/images/pic.jpg" alt="Error" />';

D:/website/images/pic.jpg is not a valid URI. The image tag in HTML requires a valid URI for the SRC attribute.

Please see the HTML documentation of your choice (eg Mozilla Developer Network (MDN) ) and provide a valid URI RFC3986 instead.

最好的方法是使用相对路径:

src="/path/to/image.jpg"

images on html should always have protocol prefix like http:// or file:/// - in your case so make it like file:///d:/website/images/pic.jpg . it still does not work, verify the file exists. file name case does not matter in your windows environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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