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

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

<!--#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>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章