Copy codeThe Code is as follows:
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<Html>
<Head>
<Title> base64 encoding and decoding using XMLDOM and ADODB. Stream </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Style type = "text/css" title = "">
# Textarea1, # textarea3, # textarea5 {background-color: # EEEEEE ;}
</Style>
</Head>
<Body>
<H3> base64 encoding and decoding using XMLDOM and ADODB. Stream <H5> By: CuiXiPing (unintentional)
<H4> 1. base64 encoding of the file
<Input type = file name = "file1" id = "file1" size = "50">
<Input type = "button" value = "base64 encoding" onclick = "if (! File1.value) {alert ('select A file')} else {textarea1.value = Base64EncodeFile (file1.value)} ">
<Br>
<Textarea id = "textarea1" rows = "6" cols = "80" readOnly> </textarea>
<H4> 2. base64 encoding of text
<Input type = "button" value = "base64 encoding" onclick = "textarea3.value = Base64EncodeText (textarea2.value)">
<Br>
<Textarea id = "textarea2" rows = "4" cols = "40"> resolutely resist Japanese goods </textarea>
<Textarea id = "textarea3" rows = "4" cols = "40" readOnly> </textarea>
<H4> 3. base64 Decoding of text
<Input type = "button" value = "base64 decoding" onclick = "textarea5.value = Base64DecodeText (textarea4.value)">
<Br>
<Textarea id = "textarea4" rows = "4" cols = "40"> vOG + 9rXW1sbI1bv1 </textarea>
<Textarea id = "textarea5" rows = "4" cols = "40" readOnly> </textarea>
<Script language = "javaScript">
<! --
Function Base64EncodeFile (fileSpec ){
Var xml_dom = new ActiveXObject ("MSXML2.DOMDocument ");
Var ado_stream = new ActiveXObject ("ADODB. Stream ");
Var tmpNode = xml_dom.createElement ("tmpNode ");
TmpNode. dataType = "bin. base64 ";
Ado_stream.Type = 1; // 1 = adTypeBinary
If (ado_stream.state = 0) {// 0 = adStateClosed 1 = adStateOpen
Ado_stream.Open ();
}
Ado_stream.LoadFromFile (fileSpec );
TmpNode. nodeTypedValue = ado_stream.Read (-1); //-1 = adReadAll
Ado_stream.Close ();
Return tmpNode. text;
}
Function Base64EncodeText (TextStr ){
Var xml_dom = new ActiveXObject ("MSXML2.DOMDocument ");
Var ado_stream = new ActiveXObject ("ADODB. Stream ");
Var tmpNode = xml_dom.createElement ("tmpNode ");
TmpNode. dataType = "bin. base64 ";
Ado_stream.Charset = "gb2312 ";
Ado_stream.Type = 2; // 1 = adTypeBinary 2 = adTypeText
If (ado_stream.state = 0) {// 0 = adStateClosed 1 = adStateOpen
Ado_stream.Open ();
}
Ado_stream.WriteText (TextStr );
Ado_stream.Position = 0;
Ado_stream.Type = 1; // 1 = adTypeBinary 2 = adTypeText
TmpNode. nodeTypedValue = ado_stream.Read (-1); //-1 = adReadAll
Ado_stream.Close ();
Return tmpNode. text;
}
Function Base64DecodeText (Base64Str ){
Var xml_dom = new ActiveXObject ("MSXML2.DOMDocument ");
Var ado_stream = new ActiveXObject ("ADODB. Stream ");
Var tmpNode = xml_dom.createElement ("tmpNode ");
TmpNode. dataType = "bin. base64 ";
TmpNode. text = Base64Str;
Ado_stream.Charset = "gb2312 ";
Ado_stream.Type = 1; // 1 = adTypeBinary 2 = adTypeText
Ado_stream.Open ();
Ado_stream.Write (tmpNode. nodeTypedValue );
Ado_stream.Position = 0;
Ado_stream.Type = 2; // 1 = adTypeBinary 2 = adTypeText
Var str = ado_stream.ReadText (-1); //-1 = adReadAll
Ado_stream.Close ();
Return str;
}
// -->
</Script>
</Body>
</Html>