By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,739 Members | 2,059 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,739 IT Pros & Developers. It's quick & easy.

XMLHttpRequest / JavaScript to download files from server to local

P: 2
I am looking for an isolated piece of code that uses XmlHttpRequest/JavaScript to download files from a (specified path on a) server to local machine. The browser on the local machine (Mozilla/FireFox) does not require user interaction.
Oct 18 '08 #1
Share this Question
Share on Google+
4 Replies


Atli
Expert 5K+
P: 5,058
So you want your browser to download files and save them to the hard drive on your clients computer? And to top that, you want to do this without the user even being aware of it?

If so, then no mate. Never going to happen.

Could you imagine what would happen if web-developers could simply save stuff on your computer without you agreeing to it or even being aware of it? No computer connected to the internet would survive for more than a day.

No browser will ever give your client-side scripts access to the file-system.
Oct 18 '08 #2

P: 2
So you want your browser to download files and save them to the hard drive on your clients computer? And to top that, you want to do this without the user even being aware of it?

If so, then no mate. Never going to happen.

Could you imagine what would happen if web-developers could simply save stuff on your computer without you agreeing to it or even being aware of it? No computer connected to the internet would survive for more than a day.

No browser will ever give your client-side scripts access to the file-system.
No, the device with the browser is not a client or customer machine, but a dedicated device to reproduce multimedia content. Basically its a media player. It is programmed not to require user interaction, as the only controller of the dedicated device is also the controller of the server. Can you not work with server sockets on both sides, so that the server always accepts requests from player and vice versa. The only thing missing then is still the code on how to do this (download file from server to player via HTTP).

Here goes some comment from the device/software manufacturer:

+++
There is a way to do that [..initiate download from player]. That way is a standard way for Mozilla (or Firefox) based browsers.

You can use TCP sockets in your JavaScript applications like you usually do in C or any other general purpose language. See http://www.xulplanet.com/tutorials/mozsdk/sockets.php

You even can use server sockets in JavaScript. See http://www.xulplanet.com/tutorials/m...serverpush.php

You also can access local file system. See http://developer.mozilla.org/en/Code.../File_I%2f%2fO

You can also take a look at Mozilla jslib http://jslib.mozdev.org/

All this code requires interaction with user to ask him if he allows to perform the operation. In our player-browser [Mozilla/Firefox] this interaction is not required.

All these operations are allowed by default.
+++
The thing is I am just not a programming expert, and want only to have the right code to execute this operation.

Thanks a lot.
Oct 18 '08 #3

rnd me
Expert 100+
P: 427
you can use flash for sockets.

you can load remote files into variables, but you cannot save them on the local machine.

although in firefox and IE8, you can store up to 5mb of data using window.globalStorage.

you can store 10mb w/o permission by tunneling into flash.
Oct 20 '08 #4

P: 3
I don't know that which server side technology you are using. But if u are trying it in PHP then at first you have to make a request to your server using XMLHttpRequest object and on the server end you have to read that file's content using readfile() function. Then you should set some headers like content-type, pragma and Cache-control etc and finally echo that content on your web page using PHP 'echo' .
Oct 22 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.