最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jQueryJavaScript read imagefiles from path file - Stack Overflow

programmeradmin2浏览0评论

I have a reference how to load an image from a file:

/

but I don't know how to manually load the image by inputting or giving a string parameter that contains path file (e.g. C:\myImage\img12.jpg)

in the link, the image is directly load from the file dialog.

I have a reference how to load an image from a file:

http://jsfiddle/eD2Ez/31/

but I don't know how to manually load the image by inputting or giving a string parameter that contains path file (e.g. C:\myImage\img12.jpg)

in the link, the image is directly load from the file dialog.

Share Improve this question asked Oct 2, 2012 at 7:41 Eldon LesleyEldon Lesley 9356 gold badges20 silver badges39 bronze badges 1
  • You just can't do that locally. Only server side languages can retrieve files from this server just by specifying a path in a string. Browser side file access can only be initiated by the user selecting a file. – devnull69 Commented Oct 2, 2012 at 7:44
Add a ment  | 

2 Answers 2

Reset to default 2

Indeed, to my knowledge there is no established or even mildly known way to load local files programmatically due to security policies.

Aside from that you may want to use the onload handler on img to be sure that the image is loaded when you draw it on canvas. At the moment in some cases where the image is too big or the puter is slow you may not get the image rendered.

Check demo: http://jsfiddle/eD2Ez/38/

Experimental / Future

However, there could be a light on the horizon. There is something called FileSystem API in the works but didn't work for me (although it should).

Firstly the FileSystem API is currently implemented under vendor prefix on Chrome version 21+.

Also you have to use the flag --allow-file-access-from-files when you launch Chrome.

But even with all this, I still didn't manage to make it happen with Chrome v21 and still get SECURITY_ERR.

Check the "demo": http://jsfiddle/MQFGd/2/

Sources:

  • MDN FileSystem API
  • W3C FileSystem API
  • FileSystem API tutorial
   $('<img src="'+img.src+'"/>').insertAfter('#cvs');

Here is demo http://jsfiddle/eD2Ez/32/

发布评论

评论列表(0)

  1. 暂无评论