图片上传和修改最短的代码实现~

简单写一个。至于安全性方面自已想吧。

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值