FileUpload
帮个忙下面的怎么来实现?
1 用FileUpload
获得上传的图片的对象,并存在一个IMAGE目录中;
2 取得图片的像素等属性 --------------------编程问答-------------------- string lstrFileName = null; //上传文件路径
string lstrFileFolder = null; //存放文件路径
string lstrFileNamePath = null; //上传目录及文件名
//获得上传到服务器的目录名称,如果上传目录为空,就使用"D:\"作为缺省上传目录
if (dir.Value != "") lstrFileFolder = dir.Value; else lstrFileFolder = "D:\\";
lstrFileName = loFile.PostedFile.FileName; //获得文件名称
//注:loFile.PostedFile.FileName 返回的是通过文件对话框选择的文件名,这之中包含了文件的目录信息
lstrFileName = Path.GetFileName(lstrFileName); //去掉目录信息,返回文件名称
//判断上传目录是否存在,不存在就建立
if (!Directory.Exists(lstrFileFolder)) Directory.CreateDirectory(lstrFileFolder);
lstrFileNamePath = lstrFileFolder + lstrFileName; //得到上传目录及文件名称
loFile.PostedFile.SaveAs(lstrFileNamePath); //上传文件到服务器 --------------------编程问答-------------------- function checkImageFormat(checkdata)
'--return: A,B,C (A is image format; B is height pixels; C is width pixels; D is color depth)
flag=0 '''''''0 is not jpg/gif/png image; 1 is jpg/gif/png
'-------------------------------------------------------check jpg----------------
if flag=0 then
tempstr=Leftb(checkdata,10)
tstr=chrb(255)&chrb(216)&chrb(255)&chrb(224)&chrb(0)&chrb(16)&chrb(74)&chrb(70)&chrb(73)&chrb(70)
if strcomp(tempstr,tstr,0)=0 then
msgstr01="jpg"
lngSize = len(checkdata)
易做图Found = 0
strTarget = chrb(255) & chrb(216) & chrb(255)
易做图Found = instrb(checkdata, strTarget)
lngPos = 易做图Found + 2
ExitLoop = false
do while ExitLoop = False and lngPos < lngSize
do while ascb(midb(checkdata, lngPos, 1)) = 255 and lngPos < lngSize
lngPos = lngPos + 1
loop
if ascb(midb(checkdata, lngPos, 1)) < 192 or ascb(midb(checkdata, lngPos, 1)) > 195 then
lngMarkerSize = lngConvert2(midb(checkdata, lngPos + 1, 2))
lngPos = lngPos + lngMarkerSize + 1
else
ExitLoop = True
end if
loop
i_Height = lngConvert2(midb(checkdata, lngPos +4, 2))
i_Width = lngConvert2(midb(checkdata, lngPos +6, 2))
i_Depth = 2 ^ (ascb(midb(checkdata, lngPos + 8, 1)) * 8)
msgstr02=","& i_height & "," & i_width
flag=2
else
flag=0
end if
end if
'--------------------------------------------------check gif--------------------------------
if flag=0 then
tempstr=Leftb(checkdata,6)
tstr=chrb(71)&chrb(73)&chrb(70)&chrb(56)&chrb(57)&chrb(97)
tstr2=chrb(71)&chrb(73)&chrb(70)&chrb(56)&chrb(55)&chrb(97)
if strcomp(tempstr,tstr,0)=0 or strcomp(tempstr,tstr2)=0 then
msgstr03="gif"
i_width=lngConvert(midb(checkdata,7,2))
i_height=lngConvert(midb(checkdata,9,2))
i_Depth = 2 ^ ((ascb(midb(checkdata, 11, 1)) and 7) + 1)
msgstr04=","& i_height & ","& i_width
flag=2
else
flag=0
end if
end if
'---------------------------------------------------check png------------------------------
if flag=0 then
tempstr=Leftb(checkdata,4)
tstr=chrb(137)&chrb(80)&chrb(78)&chrb(71)
if strcomp(tempstr,tstr,0)=0 then
msgstr05="png"
i_Width = lngConvert2(midb(checkdata, 19, 2))
i_Height = lngConvert2(midb(checkdata, 23, 2))
i_Depth = lngConvert(midb(checkdata, 25, 2))
select case ascb(right(i_Depth,1))
case 0
i_Depth = 2 ^ (asc(left(i_Depth, 1)))
gfxSpex = True
case 2
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 3)
gfxSpex = True
case 3
i_Depth = 2 ^ (asc(left(i_Depth, 1))) '8
gfxSpex = True
case 4
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 2)
gfxSpex = True
case 6
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 4)
gfxSpex = True
case else
i_Depth = -1
end select
msgstr06=","& i_height & ","& i_width
flag=2
else
flag=0
end if
end if
if flag=0 then
msgstr07="no image"
end if
msgstr=msgstr01 & msgstr02 & msgstr03 & msgstr04 & msgstr05 & msgstr06 & msgstr07
checkImageFormat=msgstr
end function
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
FormSize = Request.TotalBytes
FormData = Request.BinaryRead( FormSize )
bnCRLF = chrB( 13 ) & chrB( 10 )
Divider = LEFTB( FormData, INSTRB( FormData, bnCRLF ) - 1 )
DataStart = INSTRB( FormData, bnCRLF & bnCRLF ) + 4
DataEnd = INSTRB( DataStart + 1, FormData, divider ) - DataStart
mydata=MIDB( FormData, DataStart, DataEnd )
arrayMessage=split(checkImageFormat(mydata),",")
if arrayMessage(1)>600 OR arrayMessage(2)>600 then
%>
<script language="vbscript">
alert("请选择不大于 600 * 600 像素的图片。")
window.location="pic1.asp?id=<%=session("id")%>"
</script>
<%
else
sql="select * from yk_xwwx where id=" & session("id")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, conn, adOpenDynamic, adLockPessimistic
rs("pic")=mydata
rs("picyn")=true
rs.update
rs.close
end if
%>
<script language="vbscript">
window.location="pic1.asp?id=<%=session("id")%>"
</script>
补充:.NET技术 , ASP.NET