Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
177
rated 0 times [  181] [ 4]  / answers: 1 / hits: 19253  / 11 Years ago, wed, december 11, 2013, 12:00:00

This is the script I found via google. And I've edited the file name.



Here it is :



<html>
<head>File copy in progress...Don't close this page.</head>
<script type=text/javascript>
// initialize ActiveXObject and create an object of Scripting.FileSystemObject.
var fso = new ActiveXObject(Scripting.FileSystemObject);

// copies a file to another location + overwrites the file if already exits
fso.CopyFile(file1.txt, file2.txt, 1);


fso = null;
</script>
</html>


But it is not copying anything? Actually is it possible in JavaScript to copy a file?


More From » html

 Answers
11

Turns out in the comments that the asker's goal is the folloing:



Serve a html-page via http(s)

containing javascript that directly copy/modify files on the server that served the html-page.



The answer my friend, is that as far as I'm aware you can't directly (using just client-side javascript from the browser) do that.



For starters, HTTP(S) is not a file-protocol like say.. ftp.



So, ultimately you'd either need to find a way to communicate with a network file protocol (for example ftp) with client-side javascript (I'm unaware of such a general lib, although you can do it in IE, but you'd need some developer-license registry-key's to access full network-features on windows, and you'd still need to do your own wrapping-library (or buy a specific activeX plugin, etc) to do the communication, apart from the rest of your interface).



And the IE-specific code you posted in your answer is not meant to do this either (although it could access windows-shares you have access to).



So clearly, we can kind of forget about that option.



So, since you say you already know how to do these things in php, your next step might be to add a javascript driven/enhanced (think tree-view etc) html-gui that sends commands (post or get) to your php-script that actually copies/modifies the files on your server. Ultimately you are then just recreating a php-file manager (google hint).



If you'd go the node.js way, than this kind of just replaces php and the rest of the methodology is still the same: back-end executes commands and sends results/directory-lists etc. to HTML GUI (possibly via ajax).



You see, there are plenty of more fun things to explore, you are already half way there.



Hope this helps.



EDIT:

One might cheat tough, you could download a file (and modify it) and store it in an HTML5 typed array and using http PUT (also supporting delete) storing it on the server again. Now you'd still need to handle security/user-identification... (and there php, json, some server-side handler still kicks-in once again, I'm currently not sure how apaches put-module works once enabled). Using server side includes that you have modified to display a directory-listing and some of this kind of javascript in the header might make a very crude file-manager.. kind of.. Not exactly copying...


[#73788] Tuesday, December 10, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lindsay

Total Points: 402
Total Questions: 109
Total Answers: 109

Location: Tuvalu
Member since Sat, Feb 11, 2023
1 Year ago
;