admin管理员组

文章数量:1317113

I am trying to do a simple thing:

Let the user choose a txt file, and save its context to be used on the client side only. no server side needed.

Is it possible ?

Thanks.

I am trying to do a simple thing:

Let the user choose a txt file, and save its context to be used on the client side only. no server side needed.

Is it possible ?

Thanks.

Share Improve this question asked Dec 2, 2010 at 11:14 shdevshdev 2,0054 gold badges18 silver badges18 bronze badges 5
  • 6 You want to let a user save a file of their own, onto their puter? – Marko Commented Dec 2, 2010 at 11:15
  • What's the desired oute? As you've stated it, your question doesn't make sense (upload has to go somewhere), but perhaps there's another way to achieve your goals. – Talya Commented Dec 2, 2010 at 11:16
  • 1 It is, I do it all the time with File > Save / Save as ... – Valentin Flachsel Commented Dec 2, 2010 at 11:17
  • this seems like an odd thing to do – marcgg Commented Dec 2, 2010 at 11:18
  • 3 He wants to process a file, using javascript, on the client/browser. This would prevent the cycle: upload, process on server, download. – GvS Commented Dec 2, 2010 at 11:25
Add a ment  | 

5 Answers 5

Reset to default 5

It is possible to do so with HTML5 Files API as explained in these resources:
https://developer.mozilla/en-US/docs/Using_files_from_web_applications
http://www.html5rocks./en/tutorials/file/dndfiles/

I guess you mean "save its content" and conclude you want to do anything with this content on the client side, e.g. extract some parts to fill a form. Anyway saving the whole file unchanged, on the same machine where it es from, does not make sense. So the problem is not how to upload, but how to open/read a file. You can do this with a Java Applet, Flash, Silverlight, ActiveX ... just to name a few. JavaScript is not an option. It cannot access the file system.

If the html page, that is hosting your javascript, is from a remote server. This script is not trusted to do actions on your local filesystem.

<Obscure solution mode level = 1>

You can give more trust to a page, but this is something your user has to do. If this is an app/web only for use within an enterprise, you can probably do this centrally. And every browser handles this differently. So it is not something you can rely on, when you do not have a limited userbase.

<Obscure solution mode level = high>

If your (enterprise) users are using Internet Explorer, you could also create a HTML Application (simply give your html page an hta extension). These pages have full trust, but can only be started from a trusted location, or require confirmation from the user.

The only way you can acheive this successfully is to build an ActiveX type plugin/ponent (or java applet) you will have much more control of the client machine.

No. JavaScript cannot access the local filesystem.

However, you could install a webserver on your machine and e.g. run PHP on that one. Then you could do it without ever sending your data over a network connection. That would require you to do your data processing in PHP though.. probably not what you want. Or you could simply send back the data to your javascript.. but that'd be pretty awful to run an upload just to make the data available to JavaScript.

本文标签: javascriptIs it possible to quotuploadquot a file only with client side(no server involved)Stack Overflow