对“xmlhttp上传文件突破大小限制 (allforly )”几点疑问?

1、当要上传的文件小于要分割的范围时,生成的xml文件为实际文件的两倍,并显示两个相同的图片
比如我要上传10kb的1.jpg,生成的image.xml为20kb,并且显示两个1.jpg
2、怎样在上传后保存为一个实际的文件(不用生成xml文件)
就是说我要上传1.jpg,在服务端也保存为1.jpg
谢谢!
---------------------------------------------------------------

难得有人感兴趣,大家研究一下:
try{}语句改成:
st.LoadFromFile(uPic)
var db = st.Read()
var picSize = st.Size()
st.close()
var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.loadXML('

1<root></root>

');
if (picSize>200){//以前测试的时候,用一个节点装载大于300kb的文件就会出错,所以这里指定一下极限大小为200kb,大于200就分割
var txtP = splitString(ByteToStr(db),100000)
for (var i=0;i<txtP.length;i++){
var iPic = xmldoc.createElement("pic")
iPic.text = txtP[i];
xmldoc.documentElement.appendChild(iPic);
}
}else{
var iPic = xmldoc.createElement("pic")
iPic.text = ByteToStr(db);
xmldoc.documentElement.appendChild(iPic);
}
var pt = uPic.split(/[.]/g)
var picType = xmldoc.clreateElement("type")
picType.text = pt[pt.length-1].toLowerCase()//获取文件扩展名
xmldoc.documentElement.appendChild(picType)
xmlhttp.open("POST","upload.asp",true);
xmlhttp.onreadystatechange = rep
xmlhttp.send(xmldoc);

服务器端:
if xmldom.readyState=4 then
'xmldom.save Server.MapPath("image.xml")
Dim picName : picName = replace(date(),"-","") & "." & xmldom.documentElement.selectSingleNode("type").text'按日期给文件取名
dim i,a,txtP,byteP
set a = xmldom.documentElement.selectNodes("/root/pic")
txtP = ""
for i=0 to a.length-1
txtP = txtP & a(i).text
next
byteP = StrToByte(txtP)
Dim st : Set st = Server.CreateObject("adodb.stream")
st.Open
st.Type = 1
st.Write byteP'读入数据
st.saveToFile Server.MapPath(picName)'保存文件
st.Close
Response.BinaryWrite "上传成功!"
end if

Published At
Categories with Web编程
Tagged with
comments powered by Disqus