슈

스마트에디터2 게시글 삭제시 원본이미지도 삭제.

· 2026-03-14 (토) 00:23:48 · 8390 · 5

/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']}' ");

 

 

해당 원본이미지까지 삭제되는지 확인 하시면 됩니다. 

총 5명이 반응했습니다

댓글 5개

감사합니다. ^^

에디터 첨부이미지가 다른 곳에서 사용되고 있는지도 체크되면 좋겠습니다. 

좋은자료 감사합니다~~~
좋은 자료입니다. 감사합니다.
댓글을 작성하시려면 로그인이 필요합니다.
+
제목 글쓴이 날짜 조회
03-31 조회 7,070
03-16 조회 7,250
03-14 조회 8,391
03-13 조회 7,520
03-10 조회 7,256
03-09 조회 8,011
03-07 조회 9,124
03-06 조회 7,890
03-06 조회 8,161
03-05 조회 8,195
03-02 조회 7,676
02-19 조회 8,841
02-19 조회 9,283
02-18 조회 6,731
02-06 조회 9,068
02-02 조회 8,306
01-31 조회 6,998
01-25 조회 7,119
01-22 조회 7,337
01-19 조회 6,886
01-18 조회 7,031
01-17 조회 6,946
01-15 조회 7,651
01-14 조회 7,560
01-08 조회 6,952
01-07 조회 6,909
01-02 조회 7,182
25-12-31 조회 8,351
25-12-30 조회 6,812
25-12-29 조회 7,122