简体   繁体   English

是否可以仅在客户端“上传”文件? (不涉及服务器)

[英]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. 让用户选择一个txt文件,并保存其上下文仅用于客户端。 no server side needed. 不需要服务器端。

Is it possible ? 可能吗 ?

Thanks. 谢谢。

No. JavaScript cannot access the local filesystem. 不能.JavaScript无法访问本地文件系统。

However, you could install a webserver on your machine and eg run PHP on that one. 但是,您可以在计算机上安装Web服务器,例如在该计算机上运行PHP。 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. 这需要你在PHP中进行数据处理,但可能不是你想要的。 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. 或者您可以简单地将数据发送回您的javascript ..但是,为了使数据可用于JavaScript,运行上传非常糟糕。

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

If the html page, that is hosting your javascript, is from a remote server. 如果托管您的javascript的html页面来自远程服务器。 This script is not trusted to do actions on your local filesystem. 不信任此脚本在本地文件系统上执行操作。

<Obscure solution mode level = 1> <模糊解决方案模式级别= 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. 如果这是仅在企业内使用的app / web,您可以集中进行此操作。 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). 如果您的(企业)用户使用的是Internet Explorer,您还可以创建一个HTML应用程序 (只需为您的html页面添加一个hta扩展名)。 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. 你可以用Java Applet,Flash,Silverlight,ActiveX来做到这一点......仅举几例。 JavaScript is not an option. JavaScript不是一个选项。 It cannot access the file system. 它无法访问文件系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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