The method of deleting document Picture by Dede
Editor to share with you Dede delete document pictures of the method, I believe that most people do not know much, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to understand it!
How does Dede delete document pictures?
Dede deletes documents and deletes pictures in articles. This function is very important for friends who do photo sites, especially when deleting collected articles, it will produce a lot of useless pictures. This program does not guarantee 100% access to pictures in Body, but during this period of personal use, I did not find any problems.
First, create the "extend.func.php" file in the "/ include" directory. Then, save the following in the "extend.func.php" file with a total of three functions:
The code is as follows:
/ / parse the body data to get the absolute address function GetPicsTruePath ($body,$litpic) {$delfiles = array (); / / store the image address data if (! empty ($litpic)) {$litpicpath = GetTruePath (); $litpicpath. = $litpic; $delfiles [] = $litpicpath / / thumbnail address} preg_match_all ("/ src= [\" |'|\ S |\ s] ([^ title= "liehuo.net" |\ / >] *) {0,} (([^ >] *)\. (gif | jpg | png)) / isU ", $body,$tmpdata); $picspath = array_unique ($tmpdata [2]); / / address of all pictures in body foreach ($picspath as $tmppath) {$path = GetTruePath () / / get the absolute path $picpath = preg_replace ("/ [a-zA-z] +:\ /\ / [^ |\ /\ s] * /",'', $tmppath); / / remove the URL part $path. = $picpath; $delfiles [] = $path;// saved processed data} return $delfiles;} / / get the article Body data function GetArcBody ($aid) {global $dsql $query = "SELECT [url=mailto:dede_addonarticle.body] dede_ addonroomle.body[ / url] FROM [url=mailto:%60dede_addonarticle] `dede_ addonroomle`WHERE [url=mailto:dede_addonarticle.aid] dede_addonarti cle.aid [/ url] ='$aid'"; $row = $dsql- > GetOne ($query); if (is_array ($row) return $row; else return false } / / write the log file function WriteToDelFiles ($msg) / / when you delete the article, log {if (empty ($msg)) $savemsg= "no message"; else $savemsg= $msg; $errorFile = dirname (_ _ FILE__).'/.. / data/del_body_file.txt';// delete the record file $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, "$arcRow = $dsql- > GetOne ($arcQuery);" below:
$arcBodyRow = GetArcBody ($aid)
2: add below line 138, that is, above "return true;":
The code is as follows:
/ / parse the resources in the Body and delete $willDelFiles = GetPicsTruePath ($arcBodyRow ['body'], $arcRow [' litpic']); $nowtime = time (); $executetime = MyDate ('Y-m-d Hizug); / / get the execution time $msg = "\ r\ nArticle title: $arcRow [title]"; WriteToDelFiles ($msg) If (! empty ($willDelFiles)) {foreach ($willDelFiles as $file) {if (file_exists ($file) & &! is_dir ($file)) {if (unlink ($file)) $msg = "\ r\ nlocation: $file\ r\ nResult: deleted successfully! \ r\ ntime: $executetime "; else $msg ="\ r\ nlocation: $file\ r\ nResult: deletion failed! \ r\ ntime: $executetime ";} else $msg ="\ r\ nlocation: $file\ r\ nResult: file not saved! \ r\ ntime: $executetime "; WriteToDelFiles ($msg);} / / END foreach} else {$msg ="\ r\ nNo data was parsed in Body\ r\ nBody raw data: $arcBodyRows\ r\ ntime: $executetime "; WriteToDelFiles ($BodyRows);}
At this point, all modifications are completed, when deleting the article, the program will analyze the picture address in Body, and then delete. And in the / data/ directory, generate a log file: del_body_file.txt.
These are all the contents of Dede's method of deleting document pictures. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!