| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 700 人关注过本帖
标题:[求助]删除数据库图片记录时删除上传的图片
只看楼主 加入收藏
thbwn
Rank: 1
等 级:新手上路
帖 子:235
专家分:0
注 册:2007-10-2
结帖率:80%
收藏
 问题点数:0 回复次数:1 
[求助]删除数据库图片记录时删除上传的图片
设置图片时上传了图片,图片名在数据库表cfplay_list中字段为upname,我想在删除图片时删除上传的图片,怎样实现?
说明:1、有的直接是外部链接,这种情况upname字段默认为0;
      2、通过复选框删除所选;
      3、我想通过隐藏的name为selectid1的input传递的数据判断是否有上传的图片,然后执行符合条件的删除指令。
      4、红色、蓝色部分为相关代码。
请高手帮帮忙!

sub main()
dim num
dim selectm,selectkey
dim pic_select
selectm=trim(request("selectm"))
selectkey=trim(request(trim("selectkey")))
    if selectkey="" then
        selectm=""
    end if
pic_select=request("pic_select")
%>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="1">
  <form name="form_search" method="post" action="?page=<%=request("page")%>">
    <tr>
      <td align="center"><table border="0" align="center" cellpadding="2" cellspacing="0">
          <tr align="center">
            
            <td><strong>关键字</strong></td>
            <td><input name="selectkey" type="text" size="15" id="selectkey" onDblClick="this.value=''" value="<%=selectkey%>"></td>
            <td><select name="selectm" id="select">
                <option value="title">按名称</option>
                <option value="url" <%if selectm="url" then%>selected="selected"<%end if%>>按地址</option>
                <option value="content" <%if selectm="content" then%>selected="selected"<%end if%>>按内容</option>
              </select>
            </td>
            <td><select name="pic_select">
                <option value="">图片不限</option>
                <option value="0" <%if pic_select="0" then%>selected="selected"<%end if%>>无图片</option>
                <option value="1" <%if pic_select="1" then%>selected="selected"<%end if%>>有图片</option>
              </select>
            </td>
            <td><input type="submit" name="Submit2" value="搜 索"></td>
          </tr>
        </table></td>
    </tr>
  </form>
</table>


    <%
'############################删除选项#######################################
<!--'定义文件夹
   dim savepath
   savepath = "plus\flash\upimage"         '设置上传目录   
    //-->
    
dim selectid,selectid1
Dim FileName,FSO,Folder,Files,Upname,Temp,i
selectid=request("selectid")
selectid1=request("selectid1")   
if request("del")="删除所选" then

if selectid1="0" then

Set FSO = Server.CreateObject("Scripting.FileSystemObject")
    FileName=Request("selectid")
    Temp=Split(FileName,",")
    For i=0 To uBound(Temp)    
    conn.execute("Delete * From cfplay_list Where upname='"&Trim(Temp(i))&"'")
    Next
else

Set FSO = Server.CreateObject("Scripting.FileSystemObject")
    FileName=Request("selectid")
    Temp=Split(FileName,",")
    For i=0 To uBound(Temp)    
    conn.execute("Delete * From cfplay_list Where upname='"&Trim(Temp(i))&"'")
    Next
    Set Folder=fso.Getfolder(server.MapPath(SavePath&"\"))
    Set files=folder.files
    For Each Upname In files
        If instr(FileName,Upname.name)>0 then
            FSO.DeleteFile(Server.MapPath(SavePath&"/"&upname.name))
        End if
    Next
    Set Folder=nothing
    Set Files=nothing
    Set Fso=nothing
end if


response.redirect Request.ServerVariables("HTTP_REFERER")
end if

'##############################删除所选结束#########################################
 
'#########################自动批量排序######################################
dim sum,autosn
sum=1
autosn=Replace(trim(Request("autosn")),"'","")
if autosn<>"" then
set rs=conn.execute("select id from cfplay_list order by "&autosn&" desc")
do while not rs.eof
conn.execute("update cfplay_list set sn="&sum&" where id="&rs("id"))
sum=sum+1
rs.movenext
loop
rs.close
set rs=nothing
end if
 
'############################排序选项#######################################
if request("sn")="排序所选" and selectid<>"" then
'response.Write ""
dim selectidlist
    selectidlist=split(selectid,", ")
'response.Write ""
 for i=0 to ubound(selectidlist)
if IsNumeric(request.form("sn"&selectidlist(i))) then
conn.execute("update cfplay_list set sn="&request.form("sn"&selectidlist(i))&" where id="&int(selectidlist(i))&"")
end if
 next

'response.redirect Request.ServerVariables("HTTP_REFERER")
'response.Redirect "?classid="&request("classid")
end if

'#############################分页显示######################################
    dim CurrentPage,totalnumber,page_count,MaxPerPage,Pagenumber
    MaxPerPage=10 '每页显示数目
    CurrentPage=request("page")
    if CurrentPage="" or not IsNumeric(CurrentPage) then
        CurrentPage=1
    else
        CurrentPage=clng(CurrentPage)
        if err then
            CurrentPage=1
            err.clear
        end if
    end if

'##########  查询过滤  ############
dim sql1
    sql1="order by sn,lasttime desc "
select case selectm
    case ""
        sql="title like '%"&selectkey&"%'"
    case "title"
        sql="title like '%"&selectkey&"%'"
    case "url"
        sql="url like '%"&selectkey&"%'"
    case "content"
        sql="content like '%"&selectkey&"%'"
    case else
        sql="1=1"
end select
if pic_select="0" then
    sql=sql&" and pic=''"
elseif pic_select="1" then
    sql=sql&" and pic<>''"
end if

Set Rs=conn.execute("Select count(id) From cfplay_list Where "&sql&" ")
totalnumber=Rs(0)
Rs.close:Set Rs=Nothing

set rs=conn.execute("select id,title,url,lrc,content,pic,addtime,lasttime,sn,upname from cfplay_list where "&sql&" "&sql1&" ")

%>
<table border="0" cellspacing="1" cellpadding="2" align=center class="tableBorder">
  <form name="form_main" method="post" action="?page=<%=request("page")%>">
    <tr>
      <th height="25" colspan="9" align="center"><strong>推荐列表</strong></th>
    </tr>
    <tr align="center" class="cmsRow">
      <td nowrap><input name="chkAll" type="checkbox" id="chkAll" onClick="CheckAll(this.form)" value="checkbox" /></td>
      <td nowrap>序号</td>
      <td nowrap>名称</td>
      <td>介绍</td>
      <td nowrap="nowrap">Url/Pic</td>
      <td nowrap>添加时间</td>
      <td nowrap>更新时间</td>
    </tr>
<%

'##########分页############          
    if err.number<>0 or (rs.eof And rs.bof) then
        Response.Write "<tr><td colspan=8 align=center class=cmsRow><font color=#ff0000>没有找到相关信息!</font></td></tr>"
       else
      if totalnumber mod MaxPerPage=0 then
             Pagenumber= totalnumber \ MaxPerPage
      else
             Pagenumber= totalnumber \ MaxPerPage+1
      end if
    RS.MoveFirst
    if CurrentPage > Pagenumber then CurrentPage = Pagenumber
       if CurrentPage<1 then CurrentPage=1
    RS.Move (CurrentPage-1) * MaxPerPage
    page_count=0    
    do while not rs.eof and page_count < Clng(MaxPerPage)
%>
    <tr class="cmsRow" onMouseOver="this.style.backgroundColor='#E4E4E4'" onMouseOut="this.style.backgroundColor=''">
      <% dim upfile
    upfile=rs("upname")
    if upfile="0" then
    %>
    <td align="center"><input name="selectid" type="checkbox" id="selectid" value="<%=rs("id")%>"><input name="selectid1" type="hidden" value="<%=rs("upname")%>"></td>
      <%else%>
      <td align="center"><input name="selectid" type="checkbox" id="selectid" value="<%=rs("upname")%>"><input name="selectid1" type="hidden" value="<%=rs("upname")%>"></td>
      <%end if%>
      <td align="center"><input type="text" name="sn<%=rs("id")%>" id="sn<%=rs("id")%>" size="5" maxlength="6" value="<%=rs("sn")%>"></td>
      <td nowrap="nowrap" width="16%"><a href="?action=manage&manage=edit&id=<%=rs("id")%>" title="点击修改"><%=rs("title")%></a></td>
      <td align="center" nowrap width="36%"><%=rs("content")%></td>
      <td align="center" width="10%"><a href="<%=rs("url")%>" target="_blank" title="点击直接打开推荐连接地址"><img src="plus/flash/toppic/link.gif" width="16" height="16" border="0" /></a>
        <%if rs("pic")<>"" then%>
        <img src="plus/flash/toppic/jpg.gif" width="16" height="16" border="0" />
        <%else%>
        <img src="plus/flash/toppic/null.gif" width="16" height="16" border="0" /> <%end if%></td>
      <td align="center" nowrap width="12%"><a style="cursor:hand;" title="<%=rs("addtime")%>"><%=FormatDateTime(rs("addtime"),2)%></a></td>
      <td align="center" nowrap width="12%"><a style="cursor:hand;" title="<%=rs("lasttime")%>"><%=FormatDateTime(rs("lasttime"),2)%></a></td>
    </tr>
    <%
        page_count=page_count+1
        rs.movenext
    loop
    end if
    rs.close
    set rs=nothing
'########################################end############################################
%>
    <tr>
      <td height="30" colspan="9" align="center" class="cmsRow"> 对选项进行操作:
        <input type="submit" name="sn" value="排序所选">
        <select name="autosn" id="select" onChange="{if(confirm('确定对以上所有内容重新排序吗?')){submit();}return false;}">
          <option value="">自动排序</option>
          <option value="addtime">按添加时间</option>
          <option value="lasttime">按更新时间</option>
          <option value="id">按数据ID</option>
          <option value="title">按名称</option>
        </select>
        <input type="submit" name="del" value="删除所选" onClick="return test();">
        <font color="#ff0000">注意:未选择则操作无效</font> </td>
    </tr>
    <tr align="center">
      <td class="cmsRow" colspan="9"><table width="95%"  border="0" cellpadding="0" cellspacing="0">
          <tr align="right">
            <td><%showpage "zh",1,"?selectm="&selectm&"&selectkey="&selectkey&"&pic_select="&pic_select&"",totalnumber,MaxPerPage,true,true,"个",CurrentPage%></td>
          </tr>
        </table></td>
    </tr>
  </form>
</table>
<%
end sub

[[it] 本帖最后由 thbwn 于 2008-5-7 18:09 编辑 [/it]]
搜索更多相关主题的帖子: 数据库 删除 记录 
2008-05-07 17:48
lili0610931
Rank: 1
等 级:新手上路
帖 子:133
专家分:0
注 册:2007-7-6
收藏
得分:0 
明天帮你看,今天回家了
2008-05-07 17:51
快速回复:[求助]删除数据库图片记录时删除上传的图片
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021773 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved