Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I tried to put one of the options below(1-4) to the page and load it, no pictured is shown.
But, when I put one of the paths to any browser's address bar(IE,FF, Chrome..), so the browser DOES show the picture.

Why the picture isn't shown when the page is loaded but DO shown if the path is pasted to BROWSER's address bar?

1: <img alt="" src="D:\images\img.png" />
2: <img alt="" src="D:/images/img.png" />
3: <img alt="" src="ftp://d:/images/img.png" />
4: <img alt="" stc="ftp://d:\images\img.png" />



Thank you
Posted
Updated 30-Dec-10 22:05pm
v2

That is because when you are providing src in img tag it's fetching image relatively path from where your application is, Webapplication is running from webserver so localhost is the only location from where you can relatively fetch image.

The second question on pasting src to browser addressbar showing the image, is that it's fetching directly from your file storage, img doesn't.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 31-Dec-10 4:31am    
The img tag fetches images from any valid URL. The browser would probably not allow for local paths though if the page was loaded from a web server. OPs problem is only a file path is not a valid URL.

Your wrote: "Webapplication is running from webserver so localhost is the only location from where you can relatively fetch image"
But you don't have to view the page from a local web server you can also view it via file URL.
file:///C:/temp/test.html
I do this all the time for testing small things.

See valery's answer.
Hiren solanki 31-Dec-10 4:36am    
That's ok manfred, But I think OP is asking that if he's using D:\img.png then it's not being fetched via browser but if he's pasting the same in browser address bar then it's showing image, I was making him understand that way.
Hi,

The src attribute is the location of the image, the tag cannot understand the absolutely path on local computer, it can be understand if it's an internet address such as src= "http://localhost/Project/images/abc.png" or relative path src="../images/abc.png" (when run on the browser this path will link to internet address)

Andy
 
Share this answer
 
Comments
Manfred Rudolf Bihy 31-Dec-10 4:35am    
See valery's post.
Hi,


Have you tried to use relative paths:
src="..\images\img.png"  


this is relative to your html document of course...

or the file: prefix:

src="file://D:/images/img.png" 


Valery.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 31-Dec-10 4:27am    
Good answer! 5+
You forgot one slash though it must be: src="file:///D:/images/img.img"
And please correct the backslashes to forward slashes for the first src
attribute.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900