
#How to delete document pictures in Dede?
Dede deletes the document and deletes the pictures in the article. This function is very important for friends who are doing picture websites, especially when deleting the collected articles, a lot of useless pictures will be generated. This The program does not guarantee that 100% of the images in the Body can be obtained, but during my personal use, I found no problems.
Recommended study: Dream Weaver cms
First, create the "extend.func.php" file in the "/include" directory. Then, save the following content in There are three functions in the "extend.func.php" file:
The code is as follows:
//解析body数据,获得所有图片的绝对地址
function GetPicsTruePath($body,$litpic)
{
$delfiles = array();//存储图片地址数据
if(!empty($litpic))
{
$litpicpath = GetTruePath();
$litpicpath .= $litpic;
$delfiles[] = $litpicpath;//缩略图地址
}
preg_match_all("/src=[\"|'|\S|\s]([^ title="liehuo.net" |\/|>]*){0,}(([^>]*)\.(gif|jpg|png))/isU",$body,$tmpdata);
$picspath = array_unique($tmpdata[2]);//body中所有图片的地址
foreach($picspath as $tmppath)
{
$path = GetTruePath();//获得绝对路径
$picpath = preg_replace("/[a-zA-z]+:\/\/[^ |\/|\s]*/",'',$tmppath);//去掉网址部分
$path .=$picpath;
$delfiles[] = $path;//保存处理后的数据
}
return $delfiles;
}
//获得文章Body数据
function GetArcBody($aid)
{
global $dsql;
$query = "SELECT [url=mailto:dede_addonarticle.body]dede_addonarticle.body[/url] FROM [url=mailto:%60dede_addonarticle]`dede_addonarticle[/url]` WHERE [url=mailto:dede_addonarticle.aid]dede_addonarticle.aid[/url] = '$aid'";
$row = $dsql->GetOne($query);
if(is_array($row))
return $row;
else
return false;
}
//写入日志文件
function WriteToDelFiles($msg)//删除文章的时候会通过此函数记录日志
{
if(empty($msg)) $savemsg="未获得消息";
else $savemsg = $msg;
$errorFile = dirname(__FILE__).'/../data/del_body_file.txt';//删除记录文件
$fp = @fopen($errorFile, 'a');
@fwrite($fp,"\r\n{$savemsg}");
@fclose($fp);
}Next open the "/dede/inc/inc_batchup.php" file.
1: Add below line 33, that is, below "$arcRow = $dsql->GetOne($arcQuery);":
$arcBodyRow = GetArcBody($aid);
2: Add below line 138, that is, above "return true;":
The code is as follows:
//解析Body中的资源,并删除
$willDelFiles = GetPicsTruePath($arcBodyRow['body'],$arcRow['litpic']);
$nowtime = time();
$executetime = MyDate('Y-m-d H:i:s',$nowtime);//获得执行时间
$msg = "\r\n文章标题:$arcRow[title]";
WriteToDelFiles($msg);
if(!empty($willDelFiles))
{
foreach($willDelFiles as $file)
{
if(file_exists($file) && !is_dir($file))
{
if(unlink($file)) $msg = "\r\n位置:$file\r\n结果:删除成功!\r\n时间:$executetime";
else $msg = "\r\n位置:$file\r\n结果:删除失败!\r\n时间:$executetime";
}
else $msg = "\r\n位置:$file\r\n结果:文件不存!\r\n时间:$executetime";
WriteToDelFiles($msg);
}//END foreach
}
else
{
$msg = "\r\n未在Body中解析到数据\r\nBody原始数据:$arcBodyRow[body]\r\n时间:$executetime";
WriteToDelFiles($msg);
}At this point, all modifications are completed. When deleting the article, the program will Analyze the image address in the Body, then delete it. And generate a log file: del_body_file.txt in the /data/ directory.
The above is the detailed content of How to delete document pictures in Dede. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment





