Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I do <img src="C:/localfile.jpg">?

Tags:

html

src

It works if the html file is local (on my C drive), but not if the html file is on a server and the image file is local. Why is that?

Any possible workarounds?

like image 628
PeterV Avatar asked Nov 03 '10 19:11

PeterV


People also ask

Why is my img src not working?

Img src Not Working That means, when a web page loads, the browser has to retrieve the image from a web server and display it on the page. The broken link icon means that the browser could not find the image. If you've just added the image, then check that you included the correct image URL in the source attribute.

Why is my image not showing HTML?

Why Is My Image Not Showing up in HTML? One of the reasons why your HTML image not showing in browser is that its file is not located in the same folder that is indicated within your tag. Also, the image may not load because the file name specified in the <img> tag does not match that of your image file.

Can img src be PNG?

The <img> tag has 2 required attributes - src and alt. The <img> tag may support (depending on the browser) the following image formats: jpeg, gif, png, apng, svg, bmp, bmp ico, png ico.


2 Answers

It would be a security vulnerability if the client could request local file system files and then use JavaScript to figure out what's in them.

The only way around this is to build an extension in a browser. Firefox extensions and IE extensions can access local resources. Chrome is much more restrictive.

like image 196
Bjorn Avatar answered Oct 22 '22 23:10

Bjorn


shouldn't you use "file://C:/localfile.jpg" instead of "C:/localfile.jpg"?

like image 20
AndreDurao Avatar answered Oct 22 '22 22:10

AndreDurao