相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
- PHP中opcode緩存簡(jiǎn)單用法分析
- thinkPHP控制器變量在模板中的顯示方法示例
- PHP move_uploaded_file() 函數(shù)(將上傳的文件移動(dòng)到新位置)
- dirname(__FILE__)的含義和應(yīng)用說(shuō)明
- thinkPHP5框架實(shí)現(xiàn)分頁(yè)查詢功能的方法示例
- PHP中單雙號(hào)與變量
- PHP獲得當(dāng)日零點(diǎn)時(shí)間戳的方法分析
- Laravel ORM對(duì)Model::find方法進(jìn)行緩存示例詳解
- PHP讀寫文件高并發(fā)處理操作實(shí)例詳解
- 【CLI】利用Curl下載文件實(shí)時(shí)進(jìn)度條顯示的實(shí)現(xiàn)
Dede刪除文檔同時(shí)刪除文章中的圖片
Dede刪除文檔同時(shí)刪除文章中的圖片,這個(gè)功能對(duì)于做圖片網(wǎng)站的朋友來(lái)說(shuō)非常重要,特別是在刪除采集回來(lái)的文章時(shí),會(huì)產(chǎn)生很多無(wú)用的圖片. 本程序不保證能夠100%的獲得Body中的圖片,但在我個(gè)人使用的這段時(shí)間,沒(méi)有發(fā)現(xiàn)問(wèn)題。
首先,在"/include"目錄下建立"extend.func.php"文件. 然后,將以下內(nèi)容保存在"extend.func.php"文件中,一共三個(gè)函數(shù):
Copy to Clipboard
引用的內(nèi)容:[www.veryhuo.com]

//解析body數(shù)據(jù),獲得所有圖片的絕對(duì)地址
function GetPicsTruePath($body,$litpic)
{
$delfiles = array();//存儲(chǔ)圖片地址數(shù)據(jù)
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();//獲得絕對(duì)路徑
$picpath = preg_replace("/[a-zA-z]+:\/\/[^ |\/|\s]*/",'',$tmppath);//去掉網(wǎng)址部分
$path .=$picpath;
$delfiles[] = $path;//保存處理后的數(shù)據(jù)
}
return $delfiles;
}
//獲得文章Body數(shù)據(jù)
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)//刪除文章的時(shí)候會(huì)通過(guò)此函數(shù)記錄日志
{
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);
}
接下來(lái)打開(kāi)"/dede/inc/inc_batchup.php"文件。
1:在33行下方加入,也就是"$arcRow = $dsql->GetOne($arcQuery);"下方:
$arcBodyRow = GetArcBody($aid);
2:在138行下方加入,也就是"return true;"上方:
Copy to Clipboard
引用的內(nèi)容:[www.veryhuo.com]

//解析Body中的資源,并刪除
$willDelFiles = GetPicsTruePath($arcBodyRow['body'],$arcRow['litpic']);
$nowtime = time();
$executetime = MyDate('Y-m-d H:i:s',$nowtime);//獲得執(zhí)行時(shí)間
$msg = "\r\n文章標(biāo)題:$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結(jié)果:刪除成功!\r\n時(shí)間:$executetime";
else $msg = "\r\n位置:$file\r\n結(jié)果:刪除失?。r\n時(shí)間:$executetime";
}
else $msg = "\r\n位置:$file\r\n結(jié)果:文件不存!\r\n時(shí)間:$executetime";
WriteToDelFiles($msg);
}//END foreach
}
else
{
$msg = "\r\n未在Body中解析到數(shù)據(jù)\r\nBody原始數(shù)據(jù):$arcBodyRow[body]\r\n時(shí)間:$executetime";
WriteToDelFiles($msg);
}
至此,全部修改完成,刪除文章時(shí),程序會(huì)分析Body中的圖片地址,然后刪除.并在/data/目錄下,產(chǎn)生日志記錄文件:del_body_file.txt。