精品久久看,欧美成人久久一级c片免费,日本加勒比在线精品视频,国产一区二区三区免费大片天美,国产成人精品999在线,97理论三级九七午夜在线观看

當前位置:首頁文章首頁 IT學院 IT技術

ASP上傳功能的實例分析

作者:  來源:  發布時間:2011-6-7 15:32:13  點擊:
 '單字節字符串轉換成雙字節字符串
 function getDBfromSB(bitString)
  dim str, i
  str = ""
  for i=1 to lenb(bitString)
   str = str & chr(ascb(midb(bitString,i,1)))
  next
  getDBfromSB = str
 end function
 
 '從一個完整路徑中析出文件名稱
 function getFileNamefromPath(strPath)
  getFileNamefromPath = mid(strPath,instrrev(strPath,"\")+1)
 end function

 '判斷函數
 function iif(cond,expr1,expr2)
  if cond then
   iif = expr1
  else
   iif = expr2
  end if
 end function
 
 '定義數據庫連接字符串
 dim cnstr
 cnstr = "driver={Microsoft Access Driver (*.mdb)};dbq=" & server.MapPath("./upload.mdb")
%>

<HTML>
 <HEAD>
  <title>多個表單域或圖像同步保存到數據庫</title>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 </HEAD>
 <body>
<p>導航菜單:<b>上傳圖片</b> <a href="ShowImageListFromData2.asp">顯示圖片</a><hr></p>
 
<%
 if request.ServerVariables("REQUEST_METHOD") = "POST" then

  dim sCome, binData
  dim posB, posE, posSB, posSE
  dim binCrlf, binSub
  dim strTitle, strFileName, strContentType, posFileBegin, posFileLen, aryFileInfo
  dim i, j
  dim dicData
  dim strName,strValue
  
  binCrlf = getSBfromDB(vbcrlf)  '定義一個單字節的回車換行符
  binSub = getSBfromDB("--")    '定義一個單字節的“--”字符串
  
  set sCome = server.CreateObject("adodb.stream")
  sCome.Type = 1  '指定返回數據類型 adTypeBinary=1,adTypeText=2
  sCome.Mode = 3  '指定打開模式 adModeRead=1,adModeWrite=2,adModeReadWrite=3
  sCome.Open
  sCome.Write request.BinaryRead(request.TotalBytes)
  
  sCome.Position = 0
  binData = sCome.Read
  'response.BinaryWrite binData    '調試用:顯示提交的所有數據
  'response.Write "<hr>"       '調試用
  
  posB = instrb(binData,binSub)
  posB = instrb(posB,binData,bincrlf) + 2   '+2是加入回車換行符本身的長度
  posB = instrb(posB,binData,getSBfromDB("name=""")) + 6
  
  set dicData = server.CreateObject("scripting.dictionary")    '用來保存信息
  
  do until posB=6
   posE = instrb(posB,binData,getSBfromDB(""""))
   'Response.Write "name=" & getTextfromBin(sCome,posB,posE-posB) & "<br>"
   strName = getTextfromBin(sCome,posB,posE-posB)
   
   posB = posE + 1     '指針移動到“"”的后面
   posE = instrb(posB,binData,bincrlf)
   'Response.Write posB & "->" & posE & "<br>"
  
   if instrb(midb(binData,posB,posE-posB),getSBfromDB("filename=""")) > 0 then   '判斷成功表示這是一個file域
    posB = instrb(posB,binData,getSBfromDB("filename=""")) + 10
    posE = instrb(posB,binData,getSBfromDB(""""))
    if posE>posB then
     'response.Write "filename=" & getTextfromBin(sCome,posB,posE-posB) & "<br>"
     strFileName = getFileNamefromPath(getTextfromBin(sCome,posB,posE-posB))
     posB = instrb(posB,binData,getSBfromDb("Content-Type:")) + 14
     posE = instrb(posB,binData,bincrlf)
     'response.Write "content-type=" & getTextfromBin(sCome,posB,posE-posB) & "<br>"
     strContentType = getTextfromBin(sCome,posB,posE-posB)

     posB = posE + 4     '這個地方換了兩行,具體參看輸出的原始二進制數據
     posE = instrb(posB,binData,binSub)
     'response.Write "image data="
    
     'saveBin2File sCome,posB,posE-posB-1,server.MapPath("./") & "\test.jpg"
     'Response.Write "<img src='test.jpg' border=0><br>"
     posFileBegin = posB
     posFileLen = posE-posB-1
     strValue = strFileName & "," & strContentType & "," & posFileBegin & "," & posFileLen
    else
     'Response.Write "沒有上傳文件!" & "<br>"
     strValue = ""
    end if
   else
    posB = posE + 4     '這個地方換了兩行,具體參看輸出的原始二進制數據
    posE = instrb(posB,binData,binCrlf)
    'Response.Write "value=" & getTextfromBin(sCome,posB,posE-posB) & "<br>"  '這個后面沒有“"”,所以不用-1
    strValue = getTextfromBin(sCome,posB,posE-posB)
   end if
  
   dicData.Add strName,strValue
   
   posB = posE + 2
  
   posB = instrb(posB,binData,bincrlf) + 2
   posB = instrb(posB,binData,getSBfromDB("name=""")) + 6
  loop
  
  strTitle = dicData.Item("txtTitle")
  aryFileInfo = dicData.Item("filImage")
  if aryFileInfo <> "" then         '有文件數據上傳
   aryFileInfo = split(aryFileInfo,",")
   strFileName = aryFileInfo(0)
   strContentType = aryFileInfo(1)
   posFileBegin = aryFileInfo(2)
   posFileLen = aryFileInfo(3)
   
   sCome.Position = posFileBegin-1
   binData = sCome.Read(posFileLen)
        
   dim cn, rs, sql
   set cn = server.CreateObject("adodb.connection")
   cn.Open cnstr
   set rs = server.CreateObject("adodb.recordset")
   sql = "select title,[content-type],image from tblImage2"
   rs.Open sql,cn,1,3
   rs.AddNew
   rs.Fields("title").Value = strTitle
   rs.Fields("content-type").Value = strContentType
   
   '數據保存到數據庫
   rs.Fields("image").AppendChunk binData

首頁 上一頁 [1] [2] [3] [4]  下一頁 尾頁

相關軟件

相關文章

文章評論

軟件按字母排列: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
主站蜘蛛池模板: 日韩一页| 国产欧美一级片 | 欧亚精品一区二区三区 | 久久91亚洲精品中文字幕 | a级毛片视频免费观看 | 国产精品视频第一页 | 国产精品午夜在线观看 | 成人亚欧网站在线观看 | 欧洲精品一区二区 | 久久久精品免费观看 | 国产成人涩涩涩视频在线观看免费 | 视频在线你懂的 | 欧美日韩视频在线 | 国产精品久久免费 | 久久精品国产亚洲精品 | 天天躁日日2018躁狠狠躁 | 国产高清一级毛片在线不卡 | 日本一区二区三区四区 | 久久精品观看 | 欧美在线观看一区 | 国产大片在线看 | 四虎a级欧美在线观看 | 一区二区三区四区精品视频 | 欧美久久影院 | 欧美特欧美特级一片 | 借种免费在线观看 | 男人天堂1024 | 国产99精品 | 国产三级久久久精品三级 | 国产精品成人久久久久 | 国产精品久久久亚洲456 | 国产成人一区二区 | 橘梨纱视频一区二区在线观看 | 全国男人天堂网 | 在线观看va| 国产网站免费观看 | 日韩avapp | 国产精品久久永久免费 | www.huangse| 久青草久青草高清在线播放 | 国产在线蜜臀 |