스마트에디터2 게시글 삭제시 원본이미지도 삭제.
/bbs/delete_all.php , /bbs/delete.php 파일
if (!defined('_GNUBOARD_')) exit; 아래에 넣으세요
1) /bbs/delete_all.php , /bbs/delete.php 파일 최상단에 코드삽입
function delete_editor_images_from_content($content)
{
if (!$content) return;
preg_match_all('/<img[^>]+src=["\']?([^>"\']+)["\']?[^>]*>/i', $content, $matches);
if (empty($matches[1])) return;
$deleted = array();
foreach ($matches[1] as $src) {
if (!$src) continue;
// HTML 엔티티 복원
$src = html_entity_decode($src, ENT_QUOTES | ENT_HTML5, 'UTF-8');
// 쿼리스트링 제거
$src = preg_replace('/\?.*/', '', $src);
// URL path만 추출
$url_path = parse_url($src, PHP_URL_PATH);
if (!$url_path) {
$url_path = $src;
}
// /data/editor/ 경로만 처리
if (strpos($url_path, '/data/editor/') === false) {
continue;
}
// 절대경로 변환
$file = G5_PATH . $url_path;
// 중복 삭제 방지
if (isset($deleted[$file])) {
continue;
}
$deleted[$file] = true;
if (file_exists($file) && is_file($file)) {
@unlink($file);
}
}
}
2) /bbs/delete_all.php , /bbs/delete.php 파일 중간쯤에 //썸네일삭제 주석있는 부분
// 에디터 원본 이미지 삭제
delete_editor_images_from_content($row['wr_content']);
// 에디터 썸네일 삭제 <-------- 이부분 위에 위에 코드 삽입.
delete_editor_thumbnail($row['wr_content']);
3) delete_all.php 코드만 하나더 추가.
// 원본 에디터 이미지 삭제 (일괄삭제 대비)
delete_editor_images_from_content($write['wr_content']);
// 게시글 삭제 <-------- 이부분 위에 위에 코드 삽입.
sql_query(" delete from $write_table where wr_parent = '{$write['wr_id']}' ");
해당 원본이미지까지 삭제되는지 확인 하시면 됩니다.
댓글 1개
감사합니다. ^^
에디터 첨부이미지가 다른 곳에서 사용되고 있는지도 체크되면 좋겠습니다.