Skip to content Skip to sidebar Skip to footer

Javascript - Copy File

This is the script I found via google. And I've edited the file name. Here it is : File copy in progress...Don't close this page.

Solution 1:

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...

Solution 2:

This is a strange example. First of all, it is not common for an HTML page to interact with the local file system. I would expect that any modern browser would complain ALOT about this code with warning and setttings requirements. In addition, it is using an activeX control which should only be available on IE if anywhere.

Maybe this example is about 15 years old? That would explain a lot.

I wouldn't expect this to work out of the box on any system installed / configured in the last 5 years.

You could change the settings on your system to let it work, but I would not recommend that. You system would be powned / zombied within minutes.

I think we need to go back to what you are trying to do and why, I suspect that javascript in HTML is not the answer.


Based on the comment my suggestion is you work with node.js. You will learn a lot, have fun, and be working with a technology that is not 15 years out of date.

Go here, have fun:

http://nodejs.org/

Solution 3:

rename your file extension to .hta and double click it.. voila..

http://en.wikipedia.org/wiki/HTML_Application

Post a Comment for "Javascript - Copy File"