首页 > 织梦删除文章同时也删除图片及其它附件的方法

织梦删除文章同时也删除图片及其它附件的方法

dedecms:删除文章同时也删除图片及其它附件的方法

织梦程序在5.6版本中实现了删除图集时删了图片,但是其它频道的却不会删除,我们怎样做到DEDE删除文章同时也删除图片及其它附件呢?
晴天网小编今天来给大家分享下删除文章同时也删除附件的实现方法:

打开“/dede/inc/inc_batchup.php”,将(92 - 123行)

if(!$onlyfile)
{
    $query = "Delete From `dede_arctiny` where id='$aid' $whererecycle";
    if($dsql->ExecuteNoneQuery($query))
    {
$dsql->ExecuteNoneQuery("Delete From `dede_feedback` where aid='$aid' ");
$dsql->ExecuteNoneQuery("Delete From `dede_member_stow` where aid='$aid' ");
$dsql->ExecuteNoneQuery("Delete From `dede_taglist` where aid='$aid' ");
$dsql->ExecuteNoneQuery("Delete From `dede_erradd` where aid='$aid' ");
if($addtable != '')
{
    $dsql->ExecuteNoneQuery("Delete From `$addtable` where aid='$aid'");//2011.7.3 根据论坛反馈,修复删除文章时无法清除附加表中对应的数据 (by:织梦的鱼)
}
if($issystem != -1)
{
    $dsql->ExecuteNoneQuery("Delete From `dede_archives` where id='$aid' $whererecycle");
}
//删除相关附件
if($cfg_upload_switch == 'Y')
{
    $dsql->Execute("me", "SELECT * FROM `dede_uploads` WHERE arcid = '$aid'");
    while($row = $dsql->GetArray('me'))
    {
$addfile = $row['url'];
$aid = $row['aid'];
$dsql->ExecuteNoneQuery("Delete From `dede_uploads` where aid = '$aid' ");
$upfile = $cfg_basedir.$addfile;
if(@file_exists($upfile)) @unlink($upfile);
    }
}
    }
}

替换成:

if(!$onlyfile)
{
    //若在后台开启了删除文章的同时删除附件的选项.
    if ($cfg_upload_switch == 'Y') {
//删除图片频道的图片与主表的缩略图
if ($row["nid"] == "image") {
    $dsql->Execute("me", "SELECT * FROM `dede_uploads` WHERE arcid = '$aid'");
    while ($row = $dsql->GetArray('me')) {
$addfile = $row['url']; //当前图片的路径
$aid = $row['aid']; //自增的aid,此自增的aid就是根据文章的aid,也就是函数参数查询得到的
$dsql->ExecuteNoneQuery("Delete From `dede_uploads` where aid = '$aid' ");
$upfile = $cfg_basedir . $addfile;
if (@file_exists($upfile)) @unlink($upfile); //删除内容附件
    }
    $row_pic = $dsql->GetOne("select * from `dede_archives` where `id` = '$aid'");
    if ($row_pic["litpic"] != "") {
$upfile = $cfg_basedir . $row_pic["litpic"];
if (@file_exists($upfile)) @unlink($upfile); //删除缩略图
    }
}
//删除图片频道以外的其他频道的图片与主表的缩略图
if ($row["nid"] != "image") {
    //删除除分类信息以外的缩略图(by:晴天网q0738.com)
    $row_pic = $dsql->GetOne("select * from `dede_archives` where `id` = '$aid'");
    if (@$row_pic["litpic"] != "") {
$upfile = $cfg_basedir . $row_pic["litpic"];
if (@file_exists($upfile)) @unlink($upfile); //删除缩略图
    }
    //删除内容中的图片,首先从附加表中获取文档的内容
    $row_article = $dsql->GetOne("select * from `$addtable` where aid = '$aid'");
    $body = $row_article["body"];
    $introduce = $row_article["introduce"];
    if ($body != "") {
preg_match_all('`src=(["|'])([^]*?.(jpg|gif|png))|i$s`', $body, $body_arr);
if ($body_arr[2] != "") {
    foreach ($body_arr[2] as $val) {
$str = str_replace($GLOBALS["cfg_basehost"], "", $val);
$upfile = $cfg_basedir . $str;
// echo $upfile; exit();
if (@file_exists($upfile)) @unlink($upfile);
    }
}
    }
    //商品
    if ($introduce != "") {
preg_match_all('`src=(["|'])([^]*?).(jpg|gif|png)|i$s`', $introduce, $introduce_arr);
if ($introduce_arr[2] != "") {
    foreach ($introduce_arr[2] as $val) {
$str = str_replace($GLOBALS["cfg_basehost"], "", $val);
$upfile = $cfg_basedir . $str;
if (@file_exists($upfile)) @unlink($upfile);
    }
}
    }
    //分类信息
    if ($row["nid"] == "infos") {
$row_pic = $dsql->GetOne("select * from `dede_addoninfos` where `aid` = '$aid'");
if (@$row_pic["litpic"] != "") {
    $upfile = $cfg_basedir . $row_pic["litpic"];
    if (@file_exists($upfile)) @unlink($upfile); //删除缩略图
}
$body = $row_body["body"];
if ($body != "") {
    preg_match_all('`src=(["|'])([^]*?.(jpg|gif|png))|i$s`', $body, $body_arr);
    if ($body_arr[2] != "") {
foreach ($body_arr[2] as $val) {
    $str = str_replace($GLOBALS["cfg_basehost"], "", $val);
    $upfile = $cfg_basedir . $str;
    if (@file_exists($upfile)) @unlink($upfile);
}
    }
}
    }
}
    }
    $dsql->ExecuteNoneQuery("Delete From `dede_arctiny` where id='$aid'");
    if ($addtable != '') {
$dsql->ExecuteNoneQuery("Delete From `$addtable` where aid='$aid' "); //删除附加表信息
    }
    if ($issystem != -1) {
$dsql->ExecuteNoneQuery("Delete From `dede_archives` where id='$aid' "); //删除主表信息
    }
    $dsql->ExecuteNoneQuery("Delete From `dede_feedback` where aid='$aid' "); //删除当前文章的评论
    $dsql->ExecuteNoneQuery("Delete From `dede_member_stow` where aid='$aid' "); //删除用户文章的收藏
    $dsql->ExecuteNoneQuery("Delete From `dede_taglist` where aid='$aid' "); //删除当前文章的tag标签
    $dsql->ExecuteNoneQuery("Delete From `dede_erradd` where aid='$aid' "); //删除挑错数据表
}

DedeCMS推荐
织梦模板管理给“未知模板”命名的方法
织梦更新系统缓存增加清理冗余缓存的功能
织梦后台及网站栏目管理空白解决方法
织梦后台不支持上传bmp格式图片的解决方...
织梦标签array runphp静态生成...
织梦自定义输出热门搜索关键词