asp上传图片同时生成缩略图和一张原始大图
<%subupload_0()'使用化境无组件上传类setupload=newupfile_class''建立上传对象upload.GetData(1048576)'取得...
<%
sub upload_0() '使用化境无组件上传类
set upload=new upfile_class ''建立上传对象
upload.GetData(1048576) '取得上传数据,限制最大上传10M
if upload.err > 0 then '如果出错
select case upload.err
case 1
response.write "请先选择你要上传的文件!"
case 2
response.write "你上传的文件总大小超出了最大限制(1M)"
end select
response.end
end if
DialogType=trim(upload.form("DialogType"))
action=trim(upload.form("action"))
select case DialogType
case "pic"
UpFileType=UpFileType_pic
case "flash"
UpFileType=UpFileType_flash
case "media"
UpFileType=UpFileType_media
case "rm"
UpFileType=UpFileType_rm
case else
UpFileType=UpFileType_pic&"|"&UpFileType_flash&"|"&UpFileType_rm & "|doc|xls|ppt|rtf|txt|rar|zip|exe|pdf"
end select
for each formName in upload.file '列出所有上传了的文件
set ofile=upload.file(formName) '生成一个文件对象
oFileSize=ofile.filesize
if oFileSize<100 then
msg="请先选择你要上传的文件!"
FoundErr=True
elseif ofilesize>(MaxFileSize*1024) then
msg="文件大小超过了限制,最大只能上传" & CStr(MaxFileSize) & "K的文件!"
FoundErr=true
end if
fileExt=lcase(ofile.FileExt)
arrUpFileType=split(UpFileType,"|")
for i=0 to ubound(arrUpFileType)
if fileEXT=trim(arrUpFileType(i)) then
EnableUpload=true
exit for
end if
next
if fileEXT="asp" or fileEXT="asa" or fileEXT="aspx" then
EnableUpload=false
end if
if EnableUpload=false then
msg="这种文件类型不允许上传!\n\n只允许上传这几种文件类型:" & UpFileType
FoundErr=true
end if
strJS="<SCRIPT language=javascript>" & vbcrlf
if FoundErr<>true then
randomize
ranNum=int(900*rnd)+100
filename=SavePath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
ofile.SaveToFile Server.mappath(FileName) '保存文件
response.write "文件上传成功!"
strJS=strJS & "parent.document.form1.url.value='" & fileName & "';" & vbcrlf
strJS=strJS & "parent.document.form1.UpFileName.value='" & fileName & "';" & vbcrlf
else
strJS=strJS & "alert('" & msg & "');" & vbcrlf
strJS=strJS & "window.location='Upload_Dialog.asp?DialogType=" & DialogType & "';" & vbcrlf
end if
strJS=strJS & "</script>" & vbcrlf
response.write strJS
set file=nothing
if action="simg" then
'--------------- 上传缩略图片开始
Dim Photo
RV_img2=replace(fileName,"../UploadFiles/","")
RV_img3="../UploadFiles/"&RV_img2
Set Photo = Server.CreateObject("Persits.Jpeg")
Photo.Open Server.MapPath("../UploadFiles/"&RV_img3)
Photo.Width = Photo.OriginalWidth/4
Photo.Height = Photo.OriginalHeight/4
Photo.Sharpen 1, 130
Photo.Save Server.MapPath("../UploadFiles/"&RV_img3)
Set Photo = Nothing
'--------------- 上传缩略图片结束
end if
next
set upload=nothing
end sub
%> 展开
sub upload_0() '使用化境无组件上传类
set upload=new upfile_class ''建立上传对象
upload.GetData(1048576) '取得上传数据,限制最大上传10M
if upload.err > 0 then '如果出错
select case upload.err
case 1
response.write "请先选择你要上传的文件!"
case 2
response.write "你上传的文件总大小超出了最大限制(1M)"
end select
response.end
end if
DialogType=trim(upload.form("DialogType"))
action=trim(upload.form("action"))
select case DialogType
case "pic"
UpFileType=UpFileType_pic
case "flash"
UpFileType=UpFileType_flash
case "media"
UpFileType=UpFileType_media
case "rm"
UpFileType=UpFileType_rm
case else
UpFileType=UpFileType_pic&"|"&UpFileType_flash&"|"&UpFileType_rm & "|doc|xls|ppt|rtf|txt|rar|zip|exe|pdf"
end select
for each formName in upload.file '列出所有上传了的文件
set ofile=upload.file(formName) '生成一个文件对象
oFileSize=ofile.filesize
if oFileSize<100 then
msg="请先选择你要上传的文件!"
FoundErr=True
elseif ofilesize>(MaxFileSize*1024) then
msg="文件大小超过了限制,最大只能上传" & CStr(MaxFileSize) & "K的文件!"
FoundErr=true
end if
fileExt=lcase(ofile.FileExt)
arrUpFileType=split(UpFileType,"|")
for i=0 to ubound(arrUpFileType)
if fileEXT=trim(arrUpFileType(i)) then
EnableUpload=true
exit for
end if
next
if fileEXT="asp" or fileEXT="asa" or fileEXT="aspx" then
EnableUpload=false
end if
if EnableUpload=false then
msg="这种文件类型不允许上传!\n\n只允许上传这几种文件类型:" & UpFileType
FoundErr=true
end if
strJS="<SCRIPT language=javascript>" & vbcrlf
if FoundErr<>true then
randomize
ranNum=int(900*rnd)+100
filename=SavePath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
ofile.SaveToFile Server.mappath(FileName) '保存文件
response.write "文件上传成功!"
strJS=strJS & "parent.document.form1.url.value='" & fileName & "';" & vbcrlf
strJS=strJS & "parent.document.form1.UpFileName.value='" & fileName & "';" & vbcrlf
else
strJS=strJS & "alert('" & msg & "');" & vbcrlf
strJS=strJS & "window.location='Upload_Dialog.asp?DialogType=" & DialogType & "';" & vbcrlf
end if
strJS=strJS & "</script>" & vbcrlf
response.write strJS
set file=nothing
if action="simg" then
'--------------- 上传缩略图片开始
Dim Photo
RV_img2=replace(fileName,"../UploadFiles/","")
RV_img3="../UploadFiles/"&RV_img2
Set Photo = Server.CreateObject("Persits.Jpeg")
Photo.Open Server.MapPath("../UploadFiles/"&RV_img3)
Photo.Width = Photo.OriginalWidth/4
Photo.Height = Photo.OriginalHeight/4
Photo.Sharpen 1, 130
Photo.Save Server.MapPath("../UploadFiles/"&RV_img3)
Set Photo = Nothing
'--------------- 上传缩略图片结束
end if
next
set upload=nothing
end sub
%> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询