I want to make a local file editor. To open some files edit them and save them back. It's ok if it only works in Chrome. Using
我想做一个本地文件编辑器。要打开一些文件,请编辑它们并将其保存回来。如果它只在Chrome中工作,那就没问题了。使用
<input type="file" id="filepicker" name="fileList" webkitdirectory multiple />
I can read all the files and draw the file tree but I want to also be able to edit and save to these files. Even create new files and folders.
我可以读取所有的文件和绘制文件树,但我也希望能够编辑和保存到这些文件。甚至创建新的文件和文件夹。
Is there any way to do it. I'm also ok with hacks that use Java or Flash or simply any other hack if HTML5 does not offer any solution.
有没有办法做到这一点。如果HTML5不提供任何解决方案,我也可以接受使用Java或Flash的黑客攻击,或者只是任何其他黑客攻击。
Thanks
谢谢
更多回答
not possible. because of the local system security.
不可能。因为本地系统的安全性。
NO, these editors are implemented by upload-edit-download
不,这些编辑器是通过上载-编辑-下载来实现的
I do not believe what you are suggesting is possible; however, there is a different approach that should solve your problem.
我不相信你的建议是可能的;然而,有一种不同的方法应该解决你的问题。
If you take Microsoft's Online Word for example... They have it setup so you save document to the cloud and then can edit them with an online copy of Microsoft Word.
如果你以微软的在线Word为例...他们对它进行了设置,这样你就可以将文档保存到云中,然后可以使用Microsoft Word的在线副本对其进行编辑。
In otherwords, the user would upload a file. Your server would then take the file, display it and allow the user to edit the file. The user would then save the changes to the file. You can then provide an option to re-download the file.
换句话说,用户将上传一个文件。然后,您的服务器将获取该文件,显示它,并允许用户编辑该文件。然后,用户将保存对该文件的更改。然后,您可以提供重新下载文件的选项。
To more closely emulate editing a file on the local file system, you can also setup a "temporarily" save on the server.
要更接近地模拟在本地文件系统上编辑文件,您还可以在服务器上设置“临时”保存。
Essentially, the user uploads a file. The server would allow the user to view and edit the file. When the user wishes to save it, instead of saving the file on the server, give it back as a download to the user.
从本质上讲,用户上传文件。服务器将允许用户查看和编辑该文件。当用户希望保存它时,不是将文件保存在服务器上,而是将其作为下载返还给用户。
After the user leaves your site you can delete the copy of the file that is saved on your server.
用户离开您的站点后,您可以删除保存在服务器上的文件副本。
The answer to this question has changed since more featues have been added to web standards.
这个问题的答案已经改变,因为Web标准中添加了更多功能。
In modern times it is possible to do what you require with the WebAPI File System API. In particular you can use window.showOpenFilePicker()
to open the browsers files system UI to get access to a file (which is represented by a (promise to) a FileSystemFileHandle
object. In the same vein you can use say window.showSaveFilePicker()
to save data to a local file.
在现代,可以使用WebAPI文件系统API执行您需要的操作。特别是,您可以使用window.showOpenFilePicker()打开浏览器的文件系统UI来访问文件(由FileSystemFileHandle对象(承诺)表示)。同样,您可以使用window.showSaveFilePicker()将数据保存到本地文件。
Do bare in mind that some of the API features are gated by user activation, which means for example that you can only open a request to get access to a file by say running a Js function as a result of a button click.
一定要记住,一些API功能是由用户激活来控制的,这意味着例如,您只能通过运行Js函数来打开访问文件的请求,这是单击按钮的结果。
更多回答
This is most my competitor pages doing. I am looking to find if there is any possible way to make it work with file system. Because this is what I actually need. If they will download a Electron version of page it's easy but there are many other similar apps that needs downloading anyway.
这就是我的竞争对手页面所做的大部分事情。我正在寻找是否有任何可能的方法,使其与文件系统的工作。因为这才是我真正需要的。如果他们要下载电子版的页面,这很容易,但无论如何,还有许多其他类似的应用程序需要下载。
@rturkek The problem what you are saying is that it is a massive security risk. Browsers are not post to let the internet access the local machine. In fact they be designed to prevent that from happening. If you want to create a local editor, the only secure and acceptable way with current technology is to create a desktop application.
@rturkek问题你所说的是这是一个巨大的安全风险。浏览器不能开机自检以允许互联网访问本地计算机。事实上,他们的设计是为了防止这种情况发生。如果您想要创建本地编辑器,使用当前技术的唯一安全和可接受的方法是创建桌面应用程序。
We can even discuss how to run executables from browser that gives access to file system. Especially if they can work in multiple OS's. But I want to make sure there is no possible way even including Java or any other tool
我们甚至可以讨论如何从允许访问文件系统的浏览器运行可执行文件。特别是如果它们可以在多个操作系统上工作。但我想确保没有任何可能的方法,甚至包括Java或任何其他工具
我是一名优秀的程序员,十分优秀!