admin管理员组文章数量:1026989
I'm using jQuery if that's any benefit; and I would like to have:
The user selects a file on the local filesystem
my javascript gets the contents of said file without going "across the wire".
I am checking the browser type and am prepared to use pletely different code for each browser. IE and FF are the two that I am currently writing for.
I am Not using php, just straight javascript on a form.
I do not want any gets, posts, submits, ajax, or any other network activity until the contents of the file have been acquired, validated, and manipulated (all of which my script will do; this question is just for getting the guts of the file).
I do not necessarily need to get the path. I don't particularly want to get the path. The generally accepted notion of "secure" having the user pick the file and my script just gets the contents. That's fine, but if I get the path I won't plain.
I've googled this a lot and haven't gotten any solution that simply works.
I've looked at Mozilla XPCOM, but the file picker nsIFilePicker requires privilege escalation, which I just don't want to deal with.
I've tried using a regular
<input type="file" onclick="fileCheck(this); return false" . . . />
with
function fileCheck ()
{
var path = obj.files[0].mozFullPath;
}
But even though you can see mozFullPath in Firebug, it does not show up for Javascript (ostensibly for security reasons).
Any ideas?
I'm using jQuery if that's any benefit; and I would like to have:
The user selects a file on the local filesystem
my javascript gets the contents of said file without going "across the wire".
I am checking the browser type and am prepared to use pletely different code for each browser. IE and FF are the two that I am currently writing for.
I am Not using php, just straight javascript on a form.
I do not want any gets, posts, submits, ajax, or any other network activity until the contents of the file have been acquired, validated, and manipulated (all of which my script will do; this question is just for getting the guts of the file).
I do not necessarily need to get the path. I don't particularly want to get the path. The generally accepted notion of "secure" having the user pick the file and my script just gets the contents. That's fine, but if I get the path I won't plain.
I've googled this a lot and haven't gotten any solution that simply works.
I've looked at Mozilla XPCOM, but the file picker nsIFilePicker requires privilege escalation, which I just don't want to deal with.
I've tried using a regular
<input type="file" onclick="fileCheck(this); return false" . . . />
with
function fileCheck ()
{
var path = obj.files[0].mozFullPath;
}
But even though you can see mozFullPath in Firebug, it does not show up for Javascript (ostensibly for security reasons).
Any ideas?
Share Improve this question asked Jan 3, 2012 at 17:05 kovacsbvkovacsbv 3514 silver badges11 bronze badges 1- I found it interesting you can get a preview/data merely by selecting a png. Not sure if this is of relevence, but it is interesting: blueimp.github./jQuery-File-Upload – NibblyPig Commented Jan 3, 2012 at 17:47
2 Answers
Reset to default 9You can; have a look at HTML5 Rocks - Reading local files in JavaScript.
You can't, for blindingly obvious security reasons.
I'm using jQuery if that's any benefit; and I would like to have:
The user selects a file on the local filesystem
my javascript gets the contents of said file without going "across the wire".
I am checking the browser type and am prepared to use pletely different code for each browser. IE and FF are the two that I am currently writing for.
I am Not using php, just straight javascript on a form.
I do not want any gets, posts, submits, ajax, or any other network activity until the contents of the file have been acquired, validated, and manipulated (all of which my script will do; this question is just for getting the guts of the file).
I do not necessarily need to get the path. I don't particularly want to get the path. The generally accepted notion of "secure" having the user pick the file and my script just gets the contents. That's fine, but if I get the path I won't plain.
I've googled this a lot and haven't gotten any solution that simply works.
I've looked at Mozilla XPCOM, but the file picker nsIFilePicker requires privilege escalation, which I just don't want to deal with.
I've tried using a regular
<input type="file" onclick="fileCheck(this); return false" . . . />
with
function fileCheck ()
{
var path = obj.files[0].mozFullPath;
}
But even though you can see mozFullPath in Firebug, it does not show up for Javascript (ostensibly for security reasons).
Any ideas?
I'm using jQuery if that's any benefit; and I would like to have:
The user selects a file on the local filesystem
my javascript gets the contents of said file without going "across the wire".
I am checking the browser type and am prepared to use pletely different code for each browser. IE and FF are the two that I am currently writing for.
I am Not using php, just straight javascript on a form.
I do not want any gets, posts, submits, ajax, or any other network activity until the contents of the file have been acquired, validated, and manipulated (all of which my script will do; this question is just for getting the guts of the file).
I do not necessarily need to get the path. I don't particularly want to get the path. The generally accepted notion of "secure" having the user pick the file and my script just gets the contents. That's fine, but if I get the path I won't plain.
I've googled this a lot and haven't gotten any solution that simply works.
I've looked at Mozilla XPCOM, but the file picker nsIFilePicker requires privilege escalation, which I just don't want to deal with.
I've tried using a regular
<input type="file" onclick="fileCheck(this); return false" . . . />
with
function fileCheck ()
{
var path = obj.files[0].mozFullPath;
}
But even though you can see mozFullPath in Firebug, it does not show up for Javascript (ostensibly for security reasons).
Any ideas?
Share Improve this question asked Jan 3, 2012 at 17:05 kovacsbvkovacsbv 3514 silver badges11 bronze badges 1- I found it interesting you can get a preview/data merely by selecting a png. Not sure if this is of relevence, but it is interesting: blueimp.github./jQuery-File-Upload – NibblyPig Commented Jan 3, 2012 at 17:47
2 Answers
Reset to default 9You can; have a look at HTML5 Rocks - Reading local files in JavaScript.
You can't, for blindingly obvious security reasons.
本文标签:
版权声明:本文标题:How to get the contents of a *user-selected* *local* file in javascript without any posts, gets, submits, etc - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1741356288a1864392.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论