将文件保存到选定目录 (javascript)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20888867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Save files into selected directory (javascript)
提问by Philip Voronov
Hello! My question is about javascript.
I want to
1. ask a user to select a directory
2. then write my bunch of files to it (probably with creating sub-directories) without interaction with user
你好!我的问题是关于 javascript。
我想
1. 要求用户选择一个目录
2. 然后在不与用户交互的情况下将我的一堆文件写入其中(可能会创建子目录)
How can I do this? And can I?
I am new in javascript and I hope for your help.
我怎样才能做到这一点?我可以吗?
我是 javascript 新手,希望对您有所帮助。
PS.
I've heard about ability to ask a user to select a path by save file dialogand then save data to selected file, but i want to ask a user oncefor selecting a directoryand then create a bunchof files in it withoutbothering a user for each one.
附注。
我听说有能力要求用户通过保存文件对话框选择路径,然后将数据保存到选定的文件,但我想要求用户一次选择一个目录,然后在其中创建一堆文件而无需打扰每个用户。
回答by cssyphus
Javascript alone doesn't have any way to access the local computer's file system for WRITE purposes. Period.
单独的 Javascript 没有任何方法可以出于写入目的访问本地计算机的文件系统。时期。
However, Downloadify, by Doug Neiner, was built for this purpose and uses a combination of Javascript and the Flash library.
然而,Downloadify,由道格Neiner,是专为这一目的而使用JavaScript和Flash库的组合。
It needs Flash 10 to work.
它需要 Flash 10 才能工作。
Alternately, you can install apache onto the computer (or better yet, a full stack like XAMPP or WAMP/MAMP/LAMP) and use PHP (with javascript/ajax) to write files onto the local file system. However, this means that the website must also be hosted locally. Probably your best bet is Downloadify
或者,您可以将 apache 安装到计算机上(或者更好的是,像 XAMPP 或 WAMP/MAMP/LAMP 这样的完整堆栈)并使用 PHP(使用 javascript/ajax)将文件写入本地文件系统。但是,这意味着该网站也必须在本地托管。可能你最好的选择是Downloadify
Resources:
资源:
https://github.com/dcneiner/Downloadify
https://github.com/dcneiner/Downloadify
How to create xml file with jquery
Save content using Jquery? Write to file