Why can't I do ?

2019-01-01 16:26发布

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?

13条回答
残风、尘缘若梦
2楼-- · 2019-01-01 16:31

I see two possibilities for what you are trying to do:

  1. You want your webpage, running on a server, to find the file on the computer that you originally designed it?

  2. You want it to fetch it from the pc that is viewing at the page?

Option 1 just doesn't make sense :)

Option 2 would be a security hole, the browser prohibits a web page (served from the web) from loading content on the viewer's machine.

Kyle Hudson told you what you need to do, but that is so basic that I find it hard to believe this is all you want to do.

查看更多
还给你的自由
3楼-- · 2019-01-01 16:32

IE 9 : If you want that the user takes a look at image before he posts it to the server : The user should ADD the website to "trusted Website list".

查看更多
骚的不知所云
4楼-- · 2019-01-01 16:33

C: is not a recognized URI scheme. Try file://c|/... instead.

查看更多
素衣白纱
5楼-- · 2019-01-01 16:36

if you use Google chrome browser you can use like this

<img src="E://bulbpro/pic_bulboff.gif"   width="150px" height="200px">

But if you use Mozila Firefox the you need to add "file " ex.

<img src="file:E://bulbpro/pic_bulboff.gif"   width="150px" height="200px">
查看更多
君临天下
6楼-- · 2019-01-01 16:42

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

查看更多
春风洒进眼中
7楼-- · 2019-01-01 16:42

Honestly the easiest way was to add file hosting to the server.

  • Open IIS

  • Add a Virtual Directory under Default Web Site

    • virtual path will be what you want to browse to in the browser. So if you choose "serverName/images you will be able to browse to it by going to http://serverName/images
    • Then add the physical path on the C: drive
  • Add the appropriate permissions to the folder on the C: drive for "NETWORK SERVICE" and "IIS AppPool\DefaultAppPool"

  • Refresh Default Web Site

  • And you're done. You can now browse to any image in that folder by navigating to http://yourServerName/whateverYourFolderNameIs/yourImage.jpg and use that url in your img src

Hope this helps someone

查看更多
登录 后发表回答