admin管理员组

文章数量:1332395

is there a way to get a file object using the directory full path of the file itself? this piece of code wont work:

var file1 = new File("D:\\path\\to\\file\\file.txt");

I need to get the file object since I have a function that has a file object as its parameter.

bryan

is there a way to get a file object using the directory full path of the file itself? this piece of code wont work:

var file1 = new File("D:\\path\\to\\file\\file.txt");

I need to get the file object since I have a function that has a file object as its parameter.

bryan

Share Improve this question asked Aug 24, 2015 at 4:44 overmindovermind 4771 gold badge8 silver badges18 bronze badges 1
  • 2 no. You can't access user's system file through js in a browser. You can however ask him to select it via an <input type="file"> element – Kaiido Commented Aug 24, 2015 at 4:49
Add a ment  | 

2 Answers 2

Reset to default 4

That would be very tragic if browsers could suddenly start accessing users' file systems without their permission.

I would suggest using <input type="file">. This way the user chooses which file they will allow the browser to access.

I would suggest you to use: <input type="file" id="fileUpload"> and get the file name using

$('input[type=file]').change(function () {
    console.log(this.files[0])
});

本文标签: javascriptget file object using full pathStack Overflow