圖片上傳和修改最短的代碼實現~

來源:互聯網
上載者:User

簡單寫一個。至於安全性方面自已想吧。

<!--#include file="conn.asp"-->
<!--#include file="upload_5xsoft.inc"-->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<body bgcolor="#CCCCCC" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<%

if Request.Querystring("Post")="OK" then

   set upload=new upload_5xsoft
   set file=upload.file("pic")
  
   if file.fileSize>0 then
      fname=file.FileName
  
   if inStr(fname,"jpg")=0 and inStr(fname,"gif")=0 and inStr(fname,"png")=0 then
      response.Write("您輸入了錯誤的圖片資訊,請<a href=# onCLICK='history.back(-1)'>返回</a>")
   response.end
   end if
  
   fname="upfile/"&fname 
  linklocal=server.mappath(session("imgpath")) '刪除伺服器圖片檔案
  Set fso=Server.CreateObject("Scripting.FileSystemObject")
  fso.DeleteFile linklocal
  set fso=nothing

 set rs=server.createobject("adodb.recordset")                         '替換資料庫圖片路徑
    sql="select  * from img  where imgpath='"&session("imgpath")&"' "
    rs.open sql,conn,3,2
    rs("imgpath")=fname
    rs.update
    rs.close
    file.saveAs Server.mappath(fname)

   end if
   j=len(fname)
   fname=Mid(fname,4,j)   
   session("upflower")=fname
   response.Write "<div style='color:white;font-size:9pt;'>圖片: <b>"&fname&"</b> 已經成功上傳並替換!</div>"
   response.end
   set file=nothing
   set upload=nothing
end if  
%><br>
<%
set rs=conn.execute("select * from img where id="&request("id")&" ")
%>
您要覆蓋的檔案是:<font color=red><%=rs("imgpath")%></font>
<%session("imgpath")=rs("imgpath")%>
<form action="<%=filename%>?Post=OK" method="post" enctype="multipart/form-data" name="up2">
  <input name="pic" type="file" id="pic">   
  <input type="submit" name="Submit3" value="上傳">
</form>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.