图片上传的asp代码

原创 2002年12月11日 13:18:00

文件夹名称:
upload:[upload0.asp,upp.asp,uploadx.asp,imag:存放上传的图片/文件的文件夹]

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
upload0.asp
<form method="POST" action="upp.asp" enctype="multipart/form-data" >
  <p> photo:   
    <input type="file" name="fruit" size="20">
<!--要同时上传多个文件就把上面的代码:<input type="file" name="fruit" size="20">多复制几次呵呵-->
    <input type="submit" value="upload" name="subbutt">  
    <input type="reset" value="reset" name="rebutt">  
</form>  <%=request("file")%>
 
 
</html> 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@       upp.asp
<%@ LANGUAGE = VBScript %>
<%Server.ScriptTimeOut=100000 %>//设置上传文件的最大运行时间
<!-- #include file="uploadx.asp" -->
<%
dim filename
path = Server.MapPath("./imag/")
filename = SaveFile("fruit",path,6000,0)//设置上传文件的最大上限
 If filename<>"" Then
If filename <> "*TooBig*" Then
    Response.redirect "upload0.asp?message="& filename &" "
Else
Response.redirect "upload0.asp?message=文件超出限制太大(<=6000K)"
End IF
End IF
%>

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@      uploadx.asp

<%
Dim FormData, FormSize, Divider, bCrLf
FormSize = Request.TotalBytes
FormData = Request.BinaryRead(FormSize)
bCrLf = ChrB(13) & ChrB(10)
Divider = LeftB(FormData, InStrB(FormData, bCrLf) - 1)
Function SaveFile(FormFileField, Path, MaxSize, SavType)
    Dim StreamObj,StreamObj1
    Set StreamObj = Server.CreateObject("ADODB.Stream")
    Set StreamObj1 = Server.CreateObject("ADODB.Stream")
    StreamObj.Mode = 3
    StreamObj1.Mode = 3
    StreamObj.Type = 1
    StreamObj1.Type = 1
    SaveFile = ""
    StartPos = LenB(Divider) + 2
    FormFileField = Chr(34) & FormFileField & Chr(34)
    If Right(Path,1) <> "/" Then
        Path = Path & "/"
    End If
    Do While StartPos > 0
        strlen = InStrB(StartPos, FormData, bCrLf) - StartPos
        SearchStr = MidB(FormData, StartPos, strlen)
        If InStr(bin2str(SearchStr), FormFileField) > 0 Then
            FileName = bin2str(GetFileName(SearchStr,path,SavType))
            If FileName <> "" Then
                FileStart = InStrB(StartPos, FormData, bCrLf & bCrLf) + 4
                FileLen = InStrB(StartPos, FormData, Divider) - 2 - FileStart
                If FileLen <= MaxSize*1024 Then
                       FileContent = MidB(FormData, FileStart, FileLen)
                    StreamObj.Open
                    StreamObj1.Open
                    StreamObj.Write FormData
                    StreamObj.Position=FileStart-1
                    StreamObj.CopyTo StreamObj1,FileLen
                    If SavType =0 Then
                        SavType = 1
                    End If
                    StreamObj1.SaveToFile Path & FileName, SavType
                    StreamObj.Close
                    StreamObj1.Close
                    If SaveFile <> "" Then
                        SaveFile = SaveFile & ","  & FileName
                    Else
                        SaveFile = FileName
                    End If
                Else
                    If SaveFile <> "" Then
                        SaveFile = SaveFile & ",*TooBig*"
                    Else
                        SaveFile = "*TooBig*"
                    End If
                End If
            End If
        End If
        If InStrB(StartPos, FormData, Divider) < 1 Then
            Exit Do
        End If
        StartPos = InStrB(StartPos, FormData, Divider) + LenB(Divider) + 2
    Loop
End Function

Function GetFormVal(FormName)
    GetFormVal = ""
    StartPos = LenB(Divider) + 2
    FormName = Chr(34) & FormName & Chr(34)
    Do While StartPos > 0
        strlen = InStrB(StartPos, FormData, bCrLf) - StartPos
        SearchStr = MidB(FormData, StartPos, strlen)
        If InStr(bin2str(SearchStr), FormName) > 0 Then
               ValStart = InStrB(StartPos, FormData, bCrLf & bCrLf) + 4
               ValLen = InStrB(StartPos, FormData, Divider) - 2 - ValStart
                  ValContent = MidB(FormData, ValStart, ValLen)
               If GetFormVal <> "" Then
                GetFormVal = GetFormVal & "," & bin2str(ValContent)
            Else
                GetFormVal = bin2str(ValContent)
            End If
        End If
        If InStrB(StartPos, FormData, Divider) < 1 Then
            Exit Do
        End If
        StartPos = InStrB(StartPos, FormData, Divider) + LenB(Divider) + 2
    Loop
End Function

Function bin2str(binstr)
   Dim varlen, clow, ccc, skipflag
   skipflag = 0
   ccc = ""
   varlen = LenB(binstr)
   For i = 1 To varlen
       If skipflag = 0 Then
          clow = MidB(binstr, i, 1)
          If AscB(clow) > 127 Then
             ccc = ccc & Chr(AscW(MidB(binstr, i + 1, 1) & clow))
             skipflag = 1
          Else
             ccc = ccc & Chr(AscB(clow))
          End If
       Else
          skipflag = 0
       End If
   Next
   bin2str = ccc
End Function

Function str2bin(str)
    For i = 1 To Len(str)
        str2bin = str2bin & ChrB(Asc(Mid(str, i, 1)))
    Next
End Function

Function GetFileName(str,path,savtype)
    Set fs = Server.CreateObject("Scripting.FileSystemObject")
    str = RightB(str,LenB(str)-InstrB(str,str2bin("filename="))-9)
    GetFileName = ""
    FileName = ""
    For i = LenB(str) To 1 Step -1
        If MidB(str, i, 1) = ChrB(Asc("/")) Then
            FileName = MidB(str, i + 1, LenB(str) - i - 1)
            Exit For
        End If
    Next
    If savtype = 0 and fs.FileExists(path & bin2str(FileName)) = True Then
        hFileName = FileName
        rFileName = ""
        For i = LenB(FileName) To 1 Step -1
            If MidB(FileName, i, 1) = ChrB(Asc(".")) Then
                hFileName = LeftB(FileName, i-1)
                rFileName = RightB(FileName, LenB(FileName)-i+1)
                Exit For
            End If
        Next
           For i = 0 to 9999
               'hFileName = hFileName & str2bin(i)
               If fs.FileExists(path & bin2str(hFileName) & i & bin2str(rFileName)) = False Then
                   FileName = hFileName & str2bin(i) & rFileName
                   Exit For
              End If
           Next
       End If
       Set fs = Nothing
       GetFileName = FileName
End Function
%>

ASP上传图片代码例子

index.asp
  • tomora
  • tomora
  • 2013年09月15日 10:25
  • 3057

asp无组件上传图片并生成缩略图

 先创建一文件夹,并创建虚拟目录或站长点。1.增加上传页xAdd.html无组件上传"POST" name="myform" action="xSave.asp" target="_self">"Pi...
  • yegengxing
  • yegengxing
  • 2008年11月07日 10:39
  • 8861

【ASP】文件上传

由于VBScript这门古老的编程语言并没有像ASP.NET,Servlet、Struts2,PHP等封装好文件上传的方法,绝对不可能一个request.form["file"]就能够拿到文件,因此处...
  • yongh701
  • yongh701
  • 2016年01月20日 17:09
  • 4725

ASP_一般处理程序_图片上传

首先创建一个文件,用于存放图片:Upload UploadImg.htm:                 window.onload = function() {             ...
  • u010909858
  • u010909858
  • 2013年11月27日 17:00
  • 1368

asp 批量同时上传文字和图片的实现。

先上代码: 表单部分: [vb] view plaincopy "-//W3C//DTD XHTML 1.0 Transitional//EN...
  • SJian123
  • SJian123
  • 2014年07月03日 10:19
  • 3318

如何实现ASP上传图片自动生成缩略图

'lj1 原图路径 'tu 图片名称 'lj2 缩 略图 存放路径 function CreatePic(lj1,tu,lj2) dim Jpeg,Path ...
  • smeyou
  • smeyou
  • 2010年08月05日 14:08
  • 1088

asp图片上传至数据库代码

dim user_id user_id=GetSession() dim Data_5xsoft Class upload_5xsoft dim objForm,objFile,Version Pub...
  • ucshng
  • ucshng
  • 2007年05月15日 12:37
  • 529

asp图片上传以后,如何删除文件夹里的图片

set fso = CreateObject("Scripting.FileSystemObject") photofile="../"&rs("images") //图片路径filepath=ser...
  • havies
  • havies
  • 2006年02月06日 14:52
  • 1123

ajax图片上传(asp.net +jquery+ashx)

一、建立Default.aspx页面 ajax图片上传 function upload(){...
  • junshangshui
  • junshangshui
  • 2011年09月21日 23:34
  • 15878

asp 上传图片到文件夹

共有文件    文件夹:shangchuan---                                     文件夹:file                              ...
  • aikni
  • aikni
  • 2009年07月18日 19:12
  • 1871
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:图片上传的asp代码
举报原因:
原因补充:

(最多只允许输入30个字)