Rocshy
Rocshy

Reputation: 3509

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" />';

?>

Upvotes: 0

Views: 5118

Answers (4)

Alexandru R
Alexandru R

Reputation: 8823

The best way is to use relative paths:

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

Upvotes: 1

thevikas
thevikas

Reputation: 1639

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.

Upvotes: 0

hakre
hakre

Reputation: 197609

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 (e.g. Mozilla Developer Network (MDN)) and provide a valid URIRFC3986 instead.

Upvotes: 2

Baba
Baba

Reputation: 95101

Yes it would not work you should use server URL instead D:/website/images/pic.jpg is a system PATH

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

Upvotes: 2

Related Questions