textfield文本框通过无组件上传(0分)

  • 主题发起人 慕荣冰靖
  • 开始时间

慕荣冰靖

Unregistered / Unconfirmed
GUEST, unregistred user!
还有就是用Inset file field可以通过无组件上传 ,把图片之类的保存在文件夹中,现在 可不可以用textfield文本框通过无组件上传,保存在文件夹中呢?
 
以下是我搞过,一定行,你修改一下既可用。希望对你有帮助。
''''''''''''''''''''''1:update.inc
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
Function GetUpload(FormData)
Dim DataStart,DivStr,DivLen,DataSize,FormFieldData
''分隔标志串(+CRLF)
DivStr = LeftB(FormData,InStrB(FormData,str2bin(VbCrLf)) + 1)
''分隔标志串长度
DivLen = LenB(DivStr)
PosOpenBoundary = InStrB(FormData,DivStr)
PosCloseBoundary = InStrB(PosOpenBoundary + 1,FormData,DivStr)
Set Fields = CreateObject("Scripting.Dictionary")
While PosOpenBoundary > 0 And PosCloseBoundary > 0
''name起始位置(name="xxxxx"),加6是因为[name="]长度为6
FieldNameStart = InStrB(PosOpenBoundary,FormData,str2bin("name=")) + 6
FieldNameSize = InStrB(FieldNameStart,FormData,ChrB(34)) - FieldNameStart ''(")的ASC值=34
FormFieldName = bin2str(MidB(FormData,FieldNameStart,FieldNameSize))
''filename起始位置(filename="xxxxx")
FieldFileNameStart = InStrB(PosOpenBoundary,FormData,str2bin("filename=")) + 10
If FieldFileNameStart < PosCloseBoundary And FieldFileNameStart > PosopenBoundary then
FieldFileNameSize = InStrB(FieldFileNameStart,FormData,ChrB(34)) - FieldFileNameStart ''(")的ASC值=34
FormFileName = bin2str(MidB(FormData,FieldFileNameStart,FieldFileNameSize))
else
FormFileName = ""
End If
''Content-Type起始位置(Content-Type: xxxxx)
FieldFileCTStart = InStrB(PosOpenBoundary,FormData,str2bin("Content-Type:")) + 14
If FieldFileCTStart < PosCloseBoundary And FieldFileCTStart > PosOpenBoundary then
FieldFileCTSize = InStrB(FieldFileCTStart,FormData,str2bin(VbCrLf &amp;
VbCrLf)) - FieldFileCTStart
FormFileCT = bin2str(MidB(FormData,FieldFileCTStart,FieldFileCTSize))
else
FormFileCT = ""
End If
''数据起始位置:2个CRLF开始
DataStart = InStrB(PosOpenBoundary,FormData,str2bin(VbCrLf &amp;
VbCrLf)) + 4
If FormFileName <> "" then
''数据长度,减1是因为数据文件的存取字节数问题(可能是AppendChunk方法的问题):
''由于字节数为奇数的图象存到数据库时会去掉最后一个字符导致图象不能正确显示,
''字节数为偶数的数据文件就不会出现这个问题,因此必须保持字节数为偶数。
DataSize = InStrB(DataStart,FormData,DivStr) - DataStart - 1
FormFieldData = MidB(FormData,DataStart,DataSize)
else
''数据长度,减2是因为分隔标志串前有一个CRLF
DataSize = InStrB(DataStart,FormData,DivStr) - DataStart - 2
FormFieldData = bin2str(MidB(FormData,DataStart,DataSize))
End If
''建立一个Dictionary集存储Form中各个Field的相关数据
Set Field = CreateUploadField()
Field.Name = FormFieldName
Field.FilePath = FormFileName
Field.FileName = GetFileName(FormFileName)
Field.ContentType = FormFileCT
Field.Length = LenB(FormFieldData)
Field.Value = FormFieldData
Fields.Add FormFieldName, Field
PosOpenBoundary = PosCloseBoundary
PosCloseBoundary = InStrB(PosOpenBoundary + 1,FormData,DivStr)
Wend
Set GetUpload = Fields
End Function
''把二进制字符串转换成普通字符串函数
Function bin2str(binstr)
Dim varlen,clow,ccc,skipflag
''中文字符Skip标志
skipflag=0
ccc = ""
If Not IsNull(binstr) then
varlen=LenB(binstr)
For i=1 To varlen
If skipflag=0 then
clow = MidB(binstr,i,1)
''判断是否中文的字符
If AscB(clow) > 127 then
''AscW会把二进制的中文双字节字符高位和低位反转,所以要先把中文的高低位反转
ccc =ccc &amp;
Chr(AscW(MidB(binstr,i+1,1) &amp;
clow))
skipflag=1
else
ccc = ccc &amp;
Chr(AscB(clow))
End If
else
skipflag=0
End If
Next
End If
bin2str = ccc
End Function

''把普通字符串转成二进制字符串函数
Function str2bin(varstr)
str2bin=""
For i=1 To Len(varstr)
varchar=mid(varstr,i,1)
varasc = Asc(varchar)
'' asc对中文字符求出来的值可能为负数,
'' 加上65536就可求出它的无符号数值
'' -1在机器内是用补码表示的0xffff,
'' 其无符号值为65535,65535=-1+65536
'' 其他负数依次类推。
If varasc<0 then
varasc = varasc + 65535
End If
''对中文的处理:把双字节低位和高位分开
If varasc>255 then
varlow = Left(Hex(Asc(varchar)),2)
varhigh = right(Hex(Asc(varchar)),2)
str2bin = str2bin &amp;
chrB("&amp;H" &amp;
varlow) &amp;
chrB("&amp;H" &amp;
varhigh)
else
str2bin = str2bin &amp;
chrB(AscB(varchar))
End If
Next
End Function
''取得文件名(去掉Path)
Function GetFileName(FullPath)
If FullPath <> "" then
FullPath = StrReverse(FullPath)
FullPath = Left(FullPath, InStr(1, FullPath, "/") - 1)
GetFileName = StrReverse(FullPath)
else
GetFileName = ""
End If
End Function
</SCRIPT>
<SCRIPT RUNAT=SERVER LANGUAGE=JSCRIPT>
function CreateUploadField(){ return new uf_Init() }
function uf_Init(){
this.Name = null
this.FileName = null
this.FilePath = null
this.ContentType = null
this.Value = null
this.Length = null
}
</SCRIPT>

'''''''2、save.asp ---保存叶面
<!--#INCLUDE FILE="upload.inc"-->
<%
'application("connectdb")="driver={SQL server};server=localhost;database=IT;uid=sa;pwd="
set cn=server.CreateObject("adodb.connection")
cn.Open application("connectdb")
set rs=server.CreateObject("adodb.recordset")
set rs1=server.CreateObject("adodb.recordset")
function lngConvert2(strTemp)
str1=leftb(strTemp,1)
str2=rightb(strTemp,1)
lngConvert2 = clng(ascb(str2) + ((ascb(str1) * 256)))
end function
function lngConvert(strTemp)
str1=leftb(strTemp,1)
str2=rightb(strTemp,1)
len1=ascb(str1)
len2=ascb(str2)
lngConvert = clng(ascb(str1) + ascb(str2) * 256)
end function
Dim FormData,FormSize
FormSize=Request.TotalBytes
FormData=Request.BinaryRead(FormSize)
'response.write "大小"&amp;FormSize&amp;"<br>"
'Response.End
'if FormSize>165535 then
if FormSize>51200 then
'response.write "文件太大,不能上传!<br>"
'response.end
%>

<SCRIPT LANGUAGE=javascript>
<!--
alert('上传的文件尺寸过大(20K)!');
history.back ();
//return(false);
//-->
</SCRIPT>
<%
Response.End
end if
Set Fields = GetUpload(FormData)
'Response.Write fields("gsmc").value&amp;"<br>"
'Response.Write fields("gsgjz").value&amp;"<br>"
'Response.Write fields("sheng").value&amp;"<br>"
'Response.Write fields("gshi").value&amp;"<br>"
'Response.Write fields("gxian").value&amp;"<br>"
'Response.Write fields("dizhi").value&amp;"<br>"
'Response.Write fields("dianhua").value&amp;"<br>"
'Response.Write fields("email").value&amp;"<br>"
'Response.Write fields("wz").value&amp;"<br>"
'Response.Write fields("fzr").value&amp;"<br>"
'Response.Write fields("lxr").value&amp;"<br>"
'Response.Write fields("xyrs").value&amp;"<br>"
'Response.Write fields("qngscz").value&amp;"<br>"
'Response.Write fields("gsxz").value&amp;"<br>"
'Response.Write fields("qyfl").value&amp;"<br>"
'Response.Write fields("fzjg").value&amp;"<br>"
'Response.Write fields("fw").value&amp;"服务对象<br>"
'Response.Write fields("li").value&amp;"<br>"
'Response.Write fields("gsjs").value&amp;"<br>"
'Response.Write fields("cpjs").value&amp;"<br>"
'Response.Write fields("zcstat").value&amp;"<br>"
'Response.End
sqlgsmc="select * from qyzl where gsmc='"&amp;trim(fields("gsmc").value)&amp;"'"
rs1.Open sqlgsmc,cn,3,1
if rs1.RecordCount>0 then
%>
<SCRIPT LANGUAGE=javascript>
<!--
alert('你输入的公司已存在!');
history.back ()
//-->
</SCRIPT>
<%
else
if fields("Request").value="Add" then

If Fields("UploadFileName").FileName<>"" then
filebz=1

tempstr=Leftb(Fields("UploadFileName").Value,10)
tstr=chrb(255)&amp;chrb(216)&amp;chrb(255)&amp;chrb(224)&amp;chrb(0)&amp;chrb(16)&amp;chrb(74)&amp;chrb(70)&amp;chrb(73)&amp;chrb(70)

flag=1
if strcomp(tempstr,tstr,0)=0 then
'response.write "是jpg格式<br>"
lngSize = len(fields("UploadFileName").value)
flgFound = 0
strTarget = chrb(255) &amp;
chrb(216) &amp;
chrb(255)
flgFound = instrb(fields("UploadFileName").value, strTarget)
if flgFound = 0 then
response.write "不是正确的jpg格式<br>"
response.end
end if
strImageType = "JPG"
lngPos = flgFound + 2
ExitLoop = false
do while ExitLoop = False and lngPos < lngSize
do
while ascb(midb(fields("UploadFileName").value, lngPos, 1)) = 255 and lngPos < lngSize
lngPos = lngPos + 1
loop
if ascb(midb(fields("UploadFileName").value, lngPos, 1)) < 192 or ascb(midb(fields("UploadFileName").value, lngPos, 1)) > 195 then
lngMarkerSize = lngConvert2(midb(fields("UploadFileName").value, lngPos + 1, 2))
lngPos = lngPos + lngMarkerSize + 1
else
ExitLoop = True
end if
loop
Height = lngConvert2(midb(fields("UploadFileName").value, lngPos +4, 2))
Width = lngConvert2(midb(fields("UploadFileName").value, lngPos +6, 2))
Depth = 2 ^ (ascb(midb(fields("UploadFileName").value, lngPos + 8, 1)) * 8)
'response.write "Height:" &amp;
height&amp;"<br>"
'response.write "Width:" &amp;
width&amp;"<br>"
if depth>1024*1024 then
depth=depth/1024
Tstr="色"
Tstr="K色"
end if
if depth>1024 then
depth=depth/1024
Tstr="M色"
end if
'response.write "Color:" &amp;
depth&amp;Tstr&amp;"<br>"
'response.end
flag=2
else
flag=0
'response.write "不是jpg格式<br>"
'Response.End
end if
if flag<>2 then
tempstr=Leftb(Fields("UploadFileName").Value,6)
tstr=chrb(71)&amp;chrb(73)&amp;chrb(70)&amp;chrb(56)&amp;chrb(57)&amp;chrb(97)
tstr2=chrb(71)&amp;chrb(73)&amp;chrb(70)&amp;chrb(56)&amp;chrb(55)&amp;chrb(97)

if strcomp(tempstr,tstr,0)=0 or strcomp(tempstr,tstr2)=0 then
'response.write "是gif格式<br>"
width=lngConvert(midb(fields("UploadFileName").value,7,2))

'if strcomp(tempstr,tstr2)=0 then
' response.write "你的文件是gif格式,但是gif中的gif87a系列图像,请选用其它的gif格式吧"
' response.end
'end if

heigh=lngConvert(midb(fields("UploadFileName").value,9,2))
Depth = 2 ^ ((ascb(midb(fields("UploadFileName").value, 11, 1)) and 7) + 1)
'response.write "<br>width:" &amp;
width
'response.write "<br>height:" &amp;
heigh
'response.write "<br>Color:" &amp;
Depth
'response.end
flag=2
else

flag=0
'response.write "不是gif格式<br>"
end if
end if
if flag<>2 then

tempstr=Leftb(Fields("UploadFileName").Value,2)
tstr=chrb(66)&amp;chrb(77)
if strcomp(tempstr,tstr,0)=0 then
'response.write "是BMP格式<br>"
width=lngConvert(midb(fields("UploadFileName").value,19,2))
heigh=lngConvert(midb(fields("UploadFileName").value,23,2))
Depth = 2 ^ (ascb(midb(Fields("UploadFileName").Value, 29, 1)))
Tstr="色"
if depth>1024*1024 then
depth=depth/1024
Tstr="色"
Tstr="K色"
end if

if depth>1024 then
depth=depth/1024
Tstr="M色"
end if
'response.write "<br>width:" &amp;
width
'response.write "<br>height:" &amp;
heigh
'response.write "<br>Color:" &amp;
Depth &amp;
Tstr
'response.end
flag=2
else

flag=0
'response.write "不是BMP格式<br>"
end if
end if
if flag<>2 then

tempstr=Leftb(Fields("UploadFileName").Value,4)
tstr=chrb(137)&amp;chrb(80)&amp;chrb(78)&amp;chrb(71)
if strcomp(tempstr,tstr,0)=0 then
'response.write "是PNG格式<br>"
Width = lngConvert2(midb(fields("UploadFileName").value, 19, 2))
Height = lngConvert2(midb(fields("UploadFileName").value, 23, 2))
Depth = lngConvert(midb(fields("UploadFileName").value, 25, 2))
select case ascb(right(Depth,1))
case 0
Depth = 2 ^ (asc(left(Depth, 1)))
gfxSpex = True
case 2
Depth = 2 ^ (asc(left(Depth, 1)) * 3)
gfxSpex = True
case 3
Depth = 2 ^ (asc(left(Depth, 1))) '8
gfxSpex = True
case 4
Depth = 2 ^ (asc(left(Depth, 1)) * 2)
gfxSpex = True
case 6
Depth = 2 ^ (asc(left(Depth, 1)) * 4)
gfxSpex = True
case else
Depth = -1
end select
'response.write "<br>width:" &amp;
width
'response.write "<br>height:" &amp;
height
'response.write "<br>Color:" &amp;
Depth
'response.end
flag=2
else

flag=0
'response.write "不是PNG格式<br>"
end if


if flag=0 then
'Response.Write "<br>"
'response.write "图像格式不对,不能保存图像"
'
%>
<SCRIPT LANGUAGE=javascript>
<!--
alert('上传的不是图形文件!');
history.back ()
//-->
</SCRIPT>
<%
Response.End
end if
end if
else
filebz=0
end if
'sql="select * from friend"
'rs.open sql,cn,1,3
sql="select * from qyzl where line_no=(select max(line_no) from qyzl)"
call rs.Open(sql,cn,3,2)
line_no=cint(rs("line_no"))+1
line_no=cstr(line_no)
rs.AddNew
rs("line_no")=line_no
rs("gsmc")=trim(fields("gsmc").value)
rs("gsgjz")=trim(fields("gsgjz").value)
rs("sheng")=trim(fields("sheng").value)
rs("shi")=trim(fields("gshi").value)
rs("xian")=trim(fields("gxian").value)
rs("dz")=trim(fields("dizhi").value)
rs("fzr")=trim(fields("fzr").value)
rs("lxr")=trim(fields("lxr").value)
rs("dh")=trim(fields("dianhua").value)
rs("email")=trim(fields("email").value)
rs("wz")=trim(fields("wz").value)
rs("fax")=trim(fields("fax").value)
rs("stat")=trim(fields("zcstat").value)
if trim(fields("xyrs").value)<>"" then

rs("xyrs")=trim(fields("xyrs").value) '现有人数
end if
if trim(fields("qngscz").value)<>"" then

rs("qngscz")=trim(fields("qngscz").value) '去年产值
end if
rs("gsxz")=trim(fields("gsxz").value)
rs("fwhy")=trim(fields("fw").value)'有问题
rs("qyfl")=trim(fields("qyfl").value)
rs("gsjs")=trim(fields("gsjs").value)
rs("cpjs")=trim(fields("cpjs").value)
rs("fzjg")=trim(fields("fzjg").value)
rs("zycp")=trim(fields("zycp").value)
If filebz=1 then
if flag>0 then
rs("logo").AppendChunk fields("UploadFileName").value
rs("filebz")=1
end if
else
rs("filebz")=0
end if
Rs.Update
rs.close
if trim(fields("li").value)<>"" then
li=trim(fields("li").value)
list=split(li,",")
listnum=ubound(list)
sql=""
for i=1 to listnum
'Response.Write list(i)&amp;"<br>"
cp=split(list(i),";")
sql=sql&amp;" insert into qycp (line_no,gsmc,cpdl,cpxl) values ('"&amp;line_no&amp;"','"&amp;trim(fields("gsmc").value)&amp;"','"&amp;cp(0)&amp;"','"&amp;cp(1)&amp;"')"
next
cn.Execute sql
end if
set rs=nothing
set cn=nothing
'response.write "图像已成功保存!!!!"&amp;filebz
'else
if trim(session("xm"))<>"" then
%>
<SCRIPT LANGUAGE=javascript>
<!--
alert('保存成功!');
//history.back ()
window.location.href='file.asp'
//-->
</SCRIPT>
<%
else
%>
<SCRIPT LANGUAGE=javascript>
<!--
alert('保存成功,并已通知管理员!');
//history.back ()
window.close();
//-->
</SCRIPT>
<%
end if
end if
end if
'else
'response.write "没选择要上传的文件!"
''Response.BinaryWrite FormData
%>
 
大哥,请允许我借宝地一用,谁能帮我看看这段asp.net上传错在哪啦?
我用的是控件htmlinputfile
Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ServerClick
File1.PostedFile.SaveAs("c:/a.jpg")
End Sub
 
顶部