露一小脸海洋星's profile星星知我心PhotosBlogLists Tools Help

Blog


    July 15

    新闻添加失败,自动删除上传过的图片(三) xmlhttp技术

    刚朋友看到我的文章又告诉我了一种xmlhttp无刷新技术,但下面的代码只能实现IE关闭时的效果,有待加强。
    <script for=window event=onbeforeunload>
    if (event.clientX > document.body.clientWidth && event.clientY < 0)
    {
        var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");      //方法二
        xmlhttp.open("post", "DeleteFile.asp", false);
        xmlhttp.send();
     }
    </script>
     
    中间的DeleteFile.asp是IE关闭时所执行的代码
     

    新闻添加失败,自动删除上传过的图片(一)

    大家在添加新闻时,总会遇到图片上传完毕后,发生一些误操作:页面关闭或者那些不可知道的错误,这时图片已经上传到硬盘上但新闻却没有添加,久而久之就会出现很多垃圾图片。
    解决的办法有很多种,比如上传完图片,可以让用户即使删除,删除了才能重新上传。第二种就是专门做一个页面进行图片的管理。
    我一直在想能不用onUnload事件,但我所知道的onUnload事件触发后只能执行alert和window.open的方法,所以只有页面关闭时弹出一个窗口才能执行删除图片的代码。
    接下来我将放出这些代码。(以下用的是风声的无组件上传,可直接调用下面页面,文件名为upfile1)
    session("dz")为存放文件的地址
     
    <!--#include file="UpLoadClass.asp"-->
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    <LINK href="../css.css" type=text/css rel=stylesheet>
    <style type="text/css">
    <!--
    body {
     background-color: #F7F7F7;
    }
    -->
    </style>
    <script language="javascript">
     function checkform()
     {
      document.form1.submit();
     
     }
    </script>
    </head>
    <body>
    <%
    Dim Action,fileurl
    Action=request.QueryString("Action")
    select case Action
           case "Add" 
        call add()
        Case "Del"
        Call Del()
        Case "modi"
        fileurl=request.QueryString("fileurl")
        if fileurl="" then
          Call main()
        Else
       Call modi()
        End IF
        case Else
        call main()
    end select
     
    ‘页面进入后的效果
    sub main()
    %>
    <form name="form1" method="post" action="upfile1.asp?Action=Add" enctype="multipart/form-data">
      <input type="file" name="S_Pic" class="inputstyle" size="40" onChange="checkform()">
    </form>
    </body>
    <%end sub%>
    </html>
    <%
    '上传图片
    sub add()
    dim upload
    set upload=New UpLoadClass
    upload.open()
    session("dz")=upload.SavePath&upload.Form("S_Pic")
    %>
    <form method="post" action="upfile1.asp?Action=Del" name="myform">
    <input type="text" value="<%=session("dz")%>" size="40" class="inputstyle"> <input type="button" value="预览" onClick="javascript:window.open('<%=Session("dz")%>','');" class="inputstyle"> <input type="submit" value="删除" class="inputstyle">
    </form>
    <%
    set upload=nothing
    end sub
     
    '显示已上传图片
    sub modi()
    session("dz")=Request.QueryString("fileurl")
    %>
    <form method="post" action="upfile1.asp?Action=Del" name="myform">
    <input type="text" value="<%=session("dz")%>" size="40" class="inputstyle"> <input type="button" value="预览" onClick="javascript:window.open('<%=session("dz")%>','');" class="inputstyle"> <input type="submit" value="删除" class="inputstyle">
    </form>
    <%
    End Sub
    ’删除图片
    Sub Del()
     Dim Fso,fileurl
     fileurl=Request.QueryString("fileurl")
     if fileurl="" then
      fileurl=session("dz")
     End IF
     Set Fso=server.CreateObject("scripting.FileSystemObject")
     if Fso.FileExists(Server.MapPath(fileurl)) then
      Fso.DeleteFile(Server.MapPath(fileurl))
     end if
    Set Fso = Nothing
    session("dz")=""
    Response.Redirect("upfile1.asp")
    End Sub
    %>
    July 14

    ASP截获sql出错信息

    on error resume next

    if err.number<>0 then
        response.write "出错了,具体信息是" & err.description
        err.clear
        response.end
    end if