简体   繁体   中英

Is it possible to “upload” a file only with client side ? (no server involved)

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.

No. JavaScript cannot access the local filesystem.

However, you could install a webserver on your machine and eg 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.

成功实现这一目标的唯一方法是构建一个ActiveX类型的插件/组件(或Java applet),您将对客户端计算机有更多的控制权。

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.

I guess you mean "save its content" and conclude you want to do anything with this content on the client side, eg extract some parts to fill a form. Anyway saving the whole file unchanged, on the same machine where it comes 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM