永发信息网

asp上传图片代码实例

答案:5  悬赏:10  手机版
解决时间 2021-04-30 09:23
asp上传图片代码实例
最佳答案

upfile.asp


<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="upload.inc"-->
<html>
<head>
<title>文件上传</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
</head>
<style type="text/css">
<!--
 @import url("jlal.css");
-->
</style>
<body>
<%
dim upload,f_folder,file,formPath,iCount,filename,fileExt,filesizemin,filesizemax


filesizemin=100
filesizemax=4000*1024 '4M
set upload=new upload_5xSoft '建立上传对象
f_folder=upload.form("upfilefolder")


'********************************列出所有上传文件***************************************************
For each formName in upload.objFile
set file=upload.file(formName)
If file.filesize>0 then


    '********************************检测文件大小***************************************************
    If file.filesize<filesizemin Then
    response.write "你上传的文件太小了 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
    ElseIf file.filesize>filesizemax then
    response.write "文件大小超过了 "&filesizemax&"字节 限制 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
    End If


    '********************************检测文件类型****************************************************
    fileExt=ucase(right(file.filename,4))
    uploadsuc=false
    Forum_upload="RAR|ZIP|SWF|JPG|PNG|GIF|DOC|TXT|CHM|PDF|ACE|MP3|WMA|WMV|MIDI|AVI|RM|RA|RMVB|MOV|XLS"
    Forumupload=split(Forum_upload,"|")
    for i=0 to ubound(Forumupload)
    if fileEXT="."&trim(Forumupload(i)) then
    uploadsuc=true
    exit for
    else
    uploadsuc=false
    end if
    next
    if uploadsuc=false then
    response.write "文件格式不正确 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
    response.end
    end if


    '********************************建立文件上传的目录文件夹****************************************
    Set upf=Server.CreateObject("Scripting.FileSystemObject")
    If Err<>0 Then
    Err.Clear
    response.write("您的服务器不支持FSO")
    response.end
    End If
    f_type= replace(fileExt,".","")
    f_name= year(now)&"-"&month(now)
    If upf.FolderExists(Server.MapPath(f_folder&"/"&f_type&"/"&f_name))=False Then
    If upf.FolderExists(Server.MapPath(f_folder&"/"&f_type))=False Then
    If upf.FolderExists(Server.MapPath(f_folder))=False Then
    upf.CreateFolder Server.MapPath(f_folder)
    upf.CreateFolder Server.MapPath(f_folder&"/"&f_type)
    upf.CreateFolder Server.MapPath(f_folder&"/"&f_type&"/"&f_name)
    Else
    upf.CreateFolder Server.MapPath(f_folder&"/"&f_type)
    upf.CreateFolder Server.MapPath(f_folder&"/"&f_type&"/"&f_name)
    End If
    Else
    upf.CreateFolder Server.MapPath(f_folder&"/"&f_type&"/"&f_name)
    End If
    End If
    f_ftn=f_folder&"/"&f_type&"/"&f_name
    Set upf=Nothing


    '********************************保存上传文件至文件夹*****************************************
    randomize
    ranNum=int(90000*rnd)+10000
    filename=f_ftn&"/"&day(now)&"-"&ranNum&"-"&file.filename
    if file.filesize>filesizemin and file.filesize<filesizemax then
    file.SaveAs Server.mappath(filename)  '保存文件
    if f_type="JPG" or f_type="GIF" or f_type="PNG" then
    response.write "<script>parent.cn_bruce.cn_content.value+='[IMG]"&filename&"[/IMG]'</script>"
    ElseIf f_type="ZIP" or f_type="RAR" or f_type="DOC" or f_type="TXT" then
    response.write "<script>parent.cn_bruce.cn_content.value+='[URL]"&filename&"[/URL]'</script>"
    'ElseIf
    else
    response.write "<script>parent.cn_bruce.cn_content.value+=' "&filename&" '</script>"
    end if
    iCount=iCount+1
    end if
set file=nothing
end if
next
set upload=nothing '删除此对象


response.write (iCount&" 个文件上传成功! <a href=# onclick=history.go(-1)>继续上传</a>")
%>
</body>
</html>

upload.asp  <meta http-equiv="content-type" content="text/html;charset=gb2312">
<form name="form" method="post" action="upfile.asp" enctype="multipart/form-data">
<input type="hidden" name="upfilefolder" value="uploadfile">
<input type="hidden" name="act" value="upload">
<input type="file" name="file11" size=40>
<input type="file" name="file12" size=40>
<input type="file" name="file13" size=40>
<input type="submit" name="Submit" value="上传">
</form>
upload.inc

<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
dim Data_5xsoft


Class upload_5xsoft
 
dim objForm,objFile,Version


Public function Form(strForm)
  strForm=lcase(strForm)
  if not objForm.exists(strForm) then
   Form=""
  else
   Form=objForm(strForm)
  end if
 end function


Public function File(strFile)
  strFile=lcase(strFile)
  if not objFile.exists(strFile) then
   set File=new FileInfo
  else
   set File=objFile(strFile)
  end if
 end function



Private Sub Class_Initialize
 dim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile
 dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
 dim iFindStart,iFindEnd
 dim iFormStart,iFormEnd,sFormName
 Version="化境HTTP上传程序 Version 2.0"
 set objForm=Server.CreateObject("Scripting.Dictionary")
 set objFile=Server.CreateObject("Scripting.Dictionary")
 if Request.TotalBytes<1 then Exit Sub
 set tStream = Server.CreateObject("adodb.stream")
 set Data_5xsoft = Server.CreateObject("adodb.stream")
 Data_5xsoft.Type = 1
 Data_5xsoft.Mode =3
 Data_5xsoft.Open
 Data_5xsoft.Write Request.BinaryRead(Request.TotalBytes)
 Data_5xsoft.Position=0
 RequestData =Data_5xsoft.Read


 iFormStart = 1
 iFormEnd = LenB(RequestData)
 vbCrlf = chrB(13) & chrB(10)
 sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)
 iStart = LenB (sStart)
 iFormStart=iFormStart+iStart+1
 while (iFormStart + 10) < iFormEnd
    iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf & vbCrlf)+3
    tStream.Type = 1
    tStream.Mode =3
    tStream.Open
    Data_5xsoft.Position = iFormStart
    Data_5xsoft.CopyTo tStream,iInfoEnd-iFormStart
    tStream.Position = 0
    tStream.Type = 2
    tStream.Charset ="gb2312"
    sInfo = tStream.ReadText
    tStream.Close
    '取得表单项目名称
    iFormStart = InStrB(iInfoEnd,RequestData,sStart)
    iFindStart = InStr(22,sInfo,"name=""",1)+6
    iFindEnd = InStr(iFindStart,sInfo,"""",1)
    sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
    '如果是文件
    if InStr (45,sInfo,"filename=""",1) > 0 then
    set theFile=new FileInfo
    '取得文件名
    iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
    iFindEnd = InStr(iFindStart,sInfo,"""",1)
    sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
    theFile.FileName=getFileName(sFileName)
    theFile.FilePath=getFilePath(sFileName)
    '取得文件类型
    iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
    iFindEnd = InStr(iFindStart,sInfo,vbCr)
    theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart)
    theFile.FileStart =iInfoEnd
    theFile.FileSize = iFormStart -iInfoEnd -3
    theFile.FormName=sFormName
    if not objFile.Exists(sFormName) then
    objFile.add sFormName,theFile
    end if
    else
    '如果是表单项目
    tStream.Type =1
    tStream.Mode =3
    tStream.Open
    Data_5xsoft.Position = iInfoEnd
    Data_5xsoft.CopyTo tStream,iFormStart-iInfoEnd-3
    tStream.Position = 0
    tStream.Type = 2
    tStream.Charset ="gb2312"
    sFormValue = tStream.ReadText
    tStream.Close
    if objForm.Exists(sFormName) then
    objForm(sFormName)=objForm(sFormName)&", "&sFormValue    
    else
    objForm.Add sFormName,sFormValue
    end if
    end if
    iFormStart=iFormStart+iStart+1
    wend
 RequestData=""
 set tStream =nothing
End Sub


Private Sub Class_Terminate
 if Request.TotalBytes>0 then
    objForm.RemoveAll
    objFile.RemoveAll
    set objForm=nothing
    set objFile=nothing
    Data_5xsoft.Close
    set Data_5xsoft =nothing
 end if
End Sub
 
 
 Private function GetFilePath(FullPath)
 If FullPath <> "" Then
  GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
 Else
  GetFilePath = ""
 End If
 End function
 
 Private function GetFileName(FullPath)
 If FullPath <> "" Then
  GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
 Else
  GetFileName = ""
 End If
 End function
End Class


Class FileInfo
 dim FormName,FileName,FilePath,FileSize,FileType,FileStart
 Private Sub Class_Initialize
  FileName = ""
  FilePath = ""
  FileSize = 0
  FileStart= 0
  FormName = ""
  FileType = ""
 End Sub
 
 Public function SaveAs(FullPath)
  dim dr,ErrorChar,i
  SaveAs=true
  if trim(fullpath)="" or FileStart=0 or FileName="" or right(fullpath,1)="/" then exit function
  set dr=CreateObject("Adodb.Stream")
  dr.Mode=3
  dr.Type=1
  dr.Open
  Data_5xsoft.position=FileStart
  Data_5xsoft.copyto dr,FileSize
  dr.SaveToFile FullPath,2
  dr.Close
  set dr=nothing
  SaveAs=false
 end function
 End Class
</SCRIPT>


——————————————————————————


如果能够帮助你解决问题,那么希望你点击“采纳”,


举手之劳,将鼓励我们继续解答其他QQ网友的问题,谢谢!

全部回答
10515484 ASP群 欢迎加入
代码太多 没法粘贴这里,有问题联系我

查找 asp无组件上传组件 ! 我给你写,写不出来人家这么好。

down.chinaz.com    down.admin5.com    down.cnzz.net     有下

加我,发你个实例
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
急…叔去死了 银行要去办死亡证 有持卡人身份
跑跑车队从一级升到两级要多少积分?
虎门是个怎样的地方?
如何马上变白
请问雅芳的BB霜好吗?
请告诉我什么样的才算不了简单而幸福的生活?
天下2 50级的战场是打60级的套装吗
人生真的像一场戏吗
DNF剑魂后跳斩怎么按不出呢?
为什么电脑关机了,电源却没关,电源风扇和CP
高中数学该怎样学好呀?!
大熊猫在古代时吃肉吗。怎么现在大部分大熊猫
求高人解梦,在一陌生河边,有多蛇,遍地都是
好友买卖要什么时候去抢资格才能开通啊???
手机给小灵通发信息怎么发?
推荐资讯
手机上哪能免费下小说
我的将军丢了!怎么解绑啊?
诺基亚C5的闹铃设置在哪?怎么找不到?
快手网红如何赚钱,快手如何赚钱?
QQ三国现在很变态吗?为什么?
玉林最出名的小吃
双击生成单独章节.exe 是用什么程序编译的?
飞车新版本什么时候出来
开了拍拍店后,有买家买我店里的东西,我应该怎
写一张借支条怎么写?有例子参照吗?
什么歌曲最好听 要最经典的两首 满分
为什么我QQ邮箱图标不亮呢!
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?