上传图片,问题,高手进来

夜若 2008-11-14 12:41:18
用asp写一个上传图片到服务器的页面
...全文
75 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
virgo2008 2008-11-14
  • 打赏
  • 举报
回复

<%
sub upload_0() '使用化境无组件上传类
set upload=new upfile_class ''建立上传对象
upload.GetData(104857600) '取得上传数据,限制最大上传100M
if upload.err > 0 then '如果出错
select case upload.err
case 1
response.write "请先选择你要上传的文件!"
case 2
response.write "你上传的文件总大小超出了最大限制(100M)"
end select
response.end
end if
PhotoUrlID=Clng(trim(upload.form("PhotoUrlID")))
SaveUpFilesPath="UploadFiles/"

if PhotoUrlID>0 then
SavePath = SaveUpFilesPath '存放上传文件的目录
else
SavePath = SaveUpFilesPath '存放上传文件的目录
end if

if right(SavePath,1)<>"/" then SavePath=SavePath&"/" '在目录后加(/)

for each formName in upload.file '列出所有上传了的文件
set ofile=upload.file(formName) '生成一个文件对象
oFileSize=ofile.filesize
if oFileSize<100 then
msg="请先选择你要上传的文件!"
FoundErr=True
else
MaxFileSize=5 '产品图片上传的最大容量 5代表5K 以此内推
select case PhotoUrlID
case 0
if oFileSize>(MaxFileSize*1024) then
msg="文件大小超过了限制,最大只能上传" & CStr(MaxFileSize) & "K的文件!"
FoundErr=true
end if
case 1
if oFileSize>(10000*1024) then
msg="文件大小超过了限制,最大只能上传10M的文件!"
FoundErr=true
end if
end select
end if

UpFileType="jpg|gif|png"

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" or fileEXT="php" or fileEXT="jsp" 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 "文件上传成功!文件大小为:" & cstr(round(oFileSize/1024)) & "K"

select case PhotoUrlID
case 0
strJS=strJS & "parent.document.f.PhotoUrl.value='" & fileName & "';" & vbcrlf
strJS=strJS & "parent.document.f.PhotoSize1.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 1
strJS=strJS & "parent.document.f.DownloadUrl.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.FileSize.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 2
strJS=strJS & "parent.document.f.PhotoUrl2.value='" & fileName & "';" & vbcrlf
strJS=strJS & "parent.document.f.PhotoSize2.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 3
strJS=strJS & "parent.document.f.CompVisualize.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize3.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 4
strJS=strJS & "parent.document.AddLink.LogoUrl.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize4.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 5
strJS=strJS & "parent.document.f.CompHonor.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize5.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
case 6
strJS=strJS & "parent.document.f.DefaultPicUrl.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize6.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf

case 7
strJS=strJS & "parent.document.myform.img.value='" & fileName & "';" & vbcrlf
'strJS=strJS & "parent.document.myform.PhotoSize6.value='" & cstr(round(oFileSize/1024)) & "';" & vbcrlf
end select
else
strJS=strJS & "alert('" & msg & "');" & vbcrlf
strJS=strJS & "history.go(-1);" & vbcrlf
end if
strJS=strJS & "</script>" & vbcrlf
response.write strJS

set file=nothing
next
set upload=nothing
end sub
%>

airsiao 2008-11-14
  • 打赏
  • 举报
回复
楼主头像很COOL
街头小贩 2008-11-14
  • 打赏
  • 举报
回复
最近在写的用的是:先锋无组件上传类(有人推荐的)

<%
function GetFilePath(FullPath,str)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, str))
Else
GetFilePath = ""
End If
End function
If Session("HRUserInfo")<>"" then
Dim upfile,fileName,serPath
Dim strtag,strUserID

strUserID=getUserID(Session("HRUserInfo"))
strtag=Request.QueryString("tag")

set upfile=new clsUp
upfile.AllowExt="gif;jpg;jpeg;"

upfile.GetData (2048000)
serPath=GetFilePath(Server.mappath("../cards/savetofile.asp"),"\")
if upfile.isErr then '如果出错
select case upfile.isErr
case 1
Response.Write "你没有上传数据呀???是不是搞错了??"
case 2
Response.Write "你上传的文件超出我们的限制,最大1M"
end select
else
fileName=upfile.AutoSave("upfile",serPath)
set upfile=nothing
end if
Else
Response.Write "您还未登陆或者操作超时"
Response.End()
End If


  • 打赏
  • 举报
回复
随便搜索,一大堆
yeah920 2008-11-14
  • 打赏
  • 举报
回复
顶起来.
airsiao 2008-11-14
  • 打赏
  • 举报
回复
用化境无组件上传
<!--#include FILE="upload.inc"-->

<%
Response.ContentType = "text/html"
Response.Charset = "gb2312"
filetype=request("filetype")
uploadname=request("uploadname")
set upload=new upload_5xSoft ''建立上传对象
set file=upload.file("Filedata") ''生成一个文件对象
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath("upload/"&filetype&"/"&uploadname) ''保存文件
end if
set file=nothing
set upload=nothing ''删除此对象
%>

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧