幸运仔 發表於 2023-6-29 00:00:00

Dede 删除文档同时文章中的图片的方法

<p>
        <span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>首先,在"/include"目录下建立"extend.func.php"文件. 然后,将以下内容保存在"extend.func.php"文件中,一共三个函数: </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <p class="right">
                <span><u>复制代码</u></span></p>
        <p>
                代码如下:</p>
</div>
<p class="msgborder" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        //解析body数据,获得所有<u>图片</u>的绝对地址 <br>
        function GetPicsTruePath($body,$litpic) <br>
        { <br>
        $delfiles = array();//存储图片地址数据 <br>
        if(!empty($litpic)) <br>
        { <br>
        $litpicpath = GetTruePath(); <br>
        $litpicpath .= $litpic; <br>
        $delfiles[] = $litpicpath;//缩略图地址 <br>
        } <br>
        preg_match_all("/src=[\"|'|\S|\s]([^ /&gt;
        <span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>接下来打开"/dede/inc/inc_batchup.php"文件。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>1:在33行下方加入,也就是"$arcRow = $dsql-&gt;GetOne($arcQuery);"下方: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>$arcBodyRow = GetArcBody($aid); </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>2:在138行下方加入,也就是"return true;"上方: </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <p class="right">
                <span><u>复制代码</u></span></p>
        <p>
                代码如下:</p>
</div>
<p class="msgborder" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        //解析Body中的资源,并删除 <br>
        $willDelFiles = GetPicsTruePath($arcBodyRow['body'],$arcRow['litpic']); <br>
        $nowtime = time(); <br>
        $executetime = MyDate('Y-m-d H:i:s',$nowtime);//获得执行时间 <br>
        $msg = "\r\n文章标题:$arcRow"; <br>
        WriteToDelFiles($msg); <br>
        if(!empty($willDelFiles)) <br>
        { <br>
        foreach($willDelFiles as $file) <br>
        { <br>
        if(file_exists($file) &amp;&amp; !is_dir($file)) <br>
        { <br>
        if(unlink($file)) $msg = "\r\n位置:$file\r\n结果:删除成功!\r\n时间:$executetime"; <br>
        else $msg = "\r\n位置:$file\r\n结果:删除失败!\r\n时间:$executetime"; <br>
        } <br>
        else $msg = "\r\n位置:$file\r\n结果:文件不存!\r\n时间:$executetime"; <br>
        WriteToDelFiles($msg); <br>
        }//END foreach <br>
        } <br>
        else <br>
        { <br>
        $msg = "\r\n未在Body中解析到数据\r\nBody原始数据:$arcBodyRow\r\n时间:$executetime"; <br>
        WriteToDelFiles($msg); <br>
        } </p>
<p>
        <br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>至此,全部修改完成,删除文章时,程序会分析Body中的图片地址,然后删除.并在/data/目录下,产生日志记录文件:del_body_file.txt。</span></p>
頁: [1]
查看完整版本: Dede 删除文档同时文章中的图片的方法