asp簡單檔案上傳源碼

來源:互聯網
上載者:User

檔案1.上傳介面檔案   upload.htm

<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>檔案上傳</title>
</head>

<body>
<form method="POST" action="SaveFile.asp">
檔案上傳:<input type="file" name="file" size="42">&nbsp;<input type="submit" value="提交" name="bb">
</form>

</body>

</html>

檔案2.儲存上傳檔案   SaveFile.asp

<%
dim file,filename,houzui
file = Request.Form("file")

if file="" then
 response.write"<script>alert('請選擇要上傳的檔案!');window.location.href='upload.htm';</script>"
else
 houzui=mid(file,InStrRev(file, "."))
 
 if houzui=".gif" or houzui=".jpg" or houzui=".bmp" then   '允許上傳的檔案類型
  filename=year(date) & month(date) & day(date) & Hour(time) & minute(time) & second(time) & houzui

  Set objStream = Server.CreateObject("ADODB.Stream")
  objStream.Type = 1
  objStream.Open
  objStream.LoadFromFile file
  objStream.SaveToFile Server.MapPath(filename),2
  objStream.Close

//============================把檔案名稱寫入資料庫,如無需要,可刪除此段代碼!
  Set conn = Server.CreateObject("ADODB.Connection")
  conn.open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("mb.mdb")
  set rs=server.CreateObject("adodb.recordset")
  rs.open "select*from img",conn,1,2
  rs.addnew
  rs("name")=filename
  rs.update
  set rs=nothing
  conn.close
  set conn=nothing
//========================================

  response.write"<script>alert('圖片上傳成功!');window.location.href='upload.htm';</script>"
 else
  response.write"<script>alert('不允許上傳" & houzui & "的格式!');window.location.href='upload.htm';</script>"
 end if
end if
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.