469,626 Members | 833 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

Is it possible to use Msxml2.XMLHTTP to upload a text file?

I have a form with an INPUT type=file in it.
I have another button that calls a function to exercise the oHTTP below.

I think I need to open with the path of the CGI script on the server.
What should the send have in it?

oHTTP.open("POST", ??????????, false);
oHTTP.send(????????????????????);

Thanks.
Jul 20 '05 #1
1 6952


Eric wrote:
I have a form with an INPUT type=file in it.
Then to upload the file let the user use an
<input type="submit">
button. I have another button that calls a function to exercise the oHTTP below.

I think I need to open with the path of the CGI script on the server.
What should the send have in it?

oHTTP.open("POST", ??????????, false);
oHTTP.send(????????????????????);


Msxml2.XMLHTTP can upload the contents of a text file, for instance you
can send a HTTP POST request where the request body is the file content:

var fso = new ActiveXObject('Scripting.FileSystemObject');
var stream = fso.OpenTextFile('test20031223.txt', 1, false);
var fileContent = stream.ReadAll();
var httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
httpRequest.open('POST', 'http://host/dir/file.asp', false);
httpRequest.setRequestHeader('Content-Type', 'text/plain');
httpRequest.setRequestHeader('Content-Length', fileContent.length);
httpRequest.send(fileContent);

The only problem is that usual from script within a HTML page loaded via
HTTP from a web server security restrictions will not allow you to read
files from the file system of the client.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Sergiusz Michalski | last post: by
3 posts views Thread by BjörnHolmberg | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.