jQuery 如何使用 JavaScript 将文件移动到其他目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17586382/
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
How can I move a file to other directory using JavaScript?
提问by user1811486
I am new to JavaScript. I need to move a file to another directory using JavaScript. How can simply move that file with JavaScript?
我是 JavaScript 的新手。我需要使用 JavaScript 将文件移动到另一个目录。如何使用 JavaScript 简单地移动该文件?
How can I solve this?
我该如何解决这个问题?
I tried this, but it didn't work....
我试过这个,但它不起作用......
<html>
<h2>Move file in JavaScript</h2>
<script language="javascript">
function moveFile(){
var object = new ActiveXObject("Scripting.FileSystemObject");
var file = object.GetFile("Table1.xml");
file.Move("./Docus/");
document.write("File is moved successfully");
}
</script>
<form>
<input type="Button" value="Move File" onClick='moveFile()'>
</form>
</html>
How can I do this, anyone?
我怎么能做到这一点,任何人?
回答by Nishu Tayal
Tried this code, working perfectly :
试过这段代码,完美运行:
function moveFile(){
var object = new ActiveXObject("Scripting.FileSystemObject");
var file = object.GetFile("C:\wamp\www\phptest.php");
file.Move("C:\wamp\");
document.write("File is moved successfully");
}
In your code, issue seems to be in file path "./Docus/". Try to put absolute path and then check.
在您的代码中,问题似乎出在文件路径“./Docus/”中。尝试放置绝对路径然后检查。
回答by Trogvar
As far as I understand the problem which you're trying to solve is to create some kind of rich UI (user interface), where user can drag-and-drop files through directory tree.
据我了解,您要解决的问题是创建某种丰富的 UI(用户界面),用户可以在其中通过目录树拖放文件。
Well that's is surely possible, but the way to make it right - and with that I mean make it cross-browser compatible and secure - is with a serverside script (PHP, ASP.Net, whatever) running behind it, providing all the data and file-system operations, with a security layer on top of it.
嗯,这肯定是可能的,但要做到这一点——我的意思是让它跨浏览器兼容和安全——是在它后面运行一个服务器端脚本(PHP、ASP.Net,等等),提供所有数据和文件系统操作,上面有一个安全层。
And if you want an unsecure, MS Internet Explorer only solution - sure you can use ActiveX objects.
如果您想要一个不安全的、仅限 MS Internet Explorer 的解决方案 - 确保您可以使用 ActiveX 对象。