打印

[XML教程] xml技术上传文件3[xml]

xml技术上传文件3[xml]

客户端

以下示例代码使用stream和msxml对象完成文件上传动作。

< 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

< /body >
< /html >

< script language=javascript >

// 上传函数
function btn_send.onclick()
{
// 创建 ado-stream 对象
var ado_stream = new activexobject("adodb.stream");


// 创建包含默认头信息和根节点的 xml文档
var xml_dom = new activexobject("msxml2.domdocument");
xml_dom.loadxml(' ');
// 指定数据类型
xml_dom.documentelement.setattribute("xmlns:dt", "urn:schemas-microsoft-com:datatypes");

// 创建一个新节点,设置其为二进制数据节点
var l_node1 = xml_dom.createelement("file1");
l_node1.datatype = "bin.base64";
// 打开stream对象,读源文件
ado_stream.type = 1; // 1=adtypebinary
ado_stream.open();
ado_stream.loadfromfile("c:\\tmp\\myfile.doc");
// 将文件内容存入xml节点
l_node1.nodetypedvalue = ado_stream.read(-1); // -1=adreadall
ado_stream.close();
xml_dom.documentelement.appendchild(l_node1);

// 可以创建多个二进制节点,一次上传多个文件

// 把xml文档发送到web服务器
var xmlhttp = new activexobject("microsoft.xmlhttp");
xmlhttp.open("post","./file_recieve.asp",false);
xmlhttp.send(xml_dom);
// 显示服务器返回的信息
div_message.innerhtml = xmlhttp.responsetext;
}
< /script >

TOP

返回顶部
AYBlue

Processed in 0.040211 second(s), 7 queries.

当前时区 GMT+8, 现在时间是 2008-11-22 18:13 京ICP备06054220号

清除 Cookies - 联系我们 - 163K.com - Archiver - WAP