fatalk1ll3r
asked on
upload file using xml/javascript
I want to upload a file using xml/javascript.
i'm trying the following example:
upload_xml.htm
************************
<HTML>
<HEAD>
<TITLE>File Send</TITLE></HEAD>
<BODY>
<INPUT id="btn_send" name="btn_send" type="button" value="FILE SEND">
<DIV id="div_message">Ready</DI V>
</BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
// files upload function
function btn_send.onclick()
{
// create ADO-stream Object
var ado_stream = new ActiveXObject("ADODB.Strea m");
// create XML document with default header and primary node
var xml_dom = new ActiveXObject("MSXML2.DOMD ocument");
xml_dom.loadXML('<?xml version="1.0" ?> <root/>');
// specify namespaces datatypes
xml_dom.documentElement.se tAttribute ("xmlns:dt ", "urn:schemas-microsoft-com :datatypes ");
// create a new node and set binary content
var l_node1 = xml_dom.createElement("fil e1");
l_node1.dataType = "bin.base64";
// open stream object and read source file
ado_stream.Type = 1; // 1=adTypeBinary
ado_stream.Open();
ado_stream.LoadFromFile("C :\\word.ps d");
// store file content into XML node
l_node1.nodeTypedValue = ado_stream.Read(-1); // -1=adReadAll
ado_stream.Close();
xml_dom.documentElement.ap pendChild( l_node1);
// we can create more XML nodes for multiple file upload
// send XML documento to Web server
var xmlhttp = new ActiveXObject("Microsoft.X MLHTTP");
xmlhttp.open("POST","uploa d_xml.asp" ,false);
xmlhttp.send(xml_dom);
// show server message in message-area
div_message.innerHTML = xmlhttp.ResponseText;
}
</SCRIPT>
********************
upload_xml.asp
<%@ LANGUAGE=VBScript%>
<% Option Explicit
Response.Expires = 0
' define variables and COM objects
dim ado_stream
dim xml_dom
dim xml_file1
' create Stream Object
set ado_stream = Server.CreateObject("ADODB .Stream")
' create XMLDOM object and load it from request ASP object
set xml_dom = Server.CreateObject("MSXML 2.DOMDocum ent")
xml_dom.load(request)
' retrieve XML node with binary content
set xml_file1 = xml_dom.selectSingleNode(" root/file1 ")
' open stream object and store XML node content into it
ado_stream.Type = 1 ' 1=adTypeBinary
ado_stream.open
ado_stream.Write xml_file1.nodeTypedValue
' save uploaded file
ado_stream.SaveToFile Server.MapPath("./") & "\word.psd",2 ' 2=adSaveCreateOverWrite
ado_stream.close
' destroy COM object
set ado_stream = Nothing
set xml_dom = Nothing
' write message to browser
Response.Write "Upload successful!"
%>
*************************
the problem is that the browser asks the user if he wants to perform that operation. Can I make this in other manner?
i'm trying the following example:
upload_xml.htm
************************
<HTML>
<HEAD>
<TITLE>File Send</TITLE></HEAD>
<BODY>
<INPUT id="btn_send" name="btn_send" type="button" value="FILE SEND">
<DIV id="div_message">Ready</DI
</BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
// files upload function
function btn_send.onclick()
{
// create ADO-stream Object
var ado_stream = new ActiveXObject("ADODB.Strea
// create XML document with default header and primary node
var xml_dom = new ActiveXObject("MSXML2.DOMD
xml_dom.loadXML('<?xml version="1.0" ?> <root/>');
// specify namespaces datatypes
xml_dom.documentElement.se
// create a new node and set binary content
var l_node1 = xml_dom.createElement("fil
l_node1.dataType = "bin.base64";
// open stream object and read source file
ado_stream.Type = 1; // 1=adTypeBinary
ado_stream.Open();
ado_stream.LoadFromFile("C
// store file content into XML node
l_node1.nodeTypedValue = ado_stream.Read(-1); // -1=adReadAll
ado_stream.Close();
xml_dom.documentElement.ap
// we can create more XML nodes for multiple file upload
// send XML documento to Web server
var xmlhttp = new ActiveXObject("Microsoft.X
xmlhttp.open("POST","uploa
xmlhttp.send(xml_dom);
// show server message in message-area
div_message.innerHTML = xmlhttp.ResponseText;
}
</SCRIPT>
********************
upload_xml.asp
<%@ LANGUAGE=VBScript%>
<% Option Explicit
Response.Expires = 0
' define variables and COM objects
dim ado_stream
dim xml_dom
dim xml_file1
' create Stream Object
set ado_stream = Server.CreateObject("ADODB
' create XMLDOM object and load it from request ASP object
set xml_dom = Server.CreateObject("MSXML
xml_dom.load(request)
' retrieve XML node with binary content
set xml_file1 = xml_dom.selectSingleNode("
' open stream object and store XML node content into it
ado_stream.Type = 1 ' 1=adTypeBinary
ado_stream.open
ado_stream.Write xml_file1.nodeTypedValue
' save uploaded file
ado_stream.SaveToFile Server.MapPath("./") & "\word.psd",2 ' 2=adSaveCreateOverWrite
ado_stream.close
' destroy COM object
set ado_stream = Nothing
set xml_dom = Nothing
' write message to browser
Response.Write "Upload successful!"
%>
*************************
the problem is that the browser asks the user if he wants to perform that operation. Can I make this in other manner?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
intranet...... but this intranet is TOO large.....
more than 1000 computers.....
hehehehe
more than 1000 computers.....
hehehehe
ASKER
ado_stream.LoadFromFile("C
to one file that exists in your computer.