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

· 2026-03-14 (토) 00:23:48 · 5174 · 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개

2026-03-15 (일) 12:37:02

감사합니다. ^^

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

2026-03-18 (수) 10:36:41
좋은자료 감사합니다~~~
감사합니다.
감사합니다
좋은 자료입니다. 감사합니다.
댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

2,788건
+
제목 글쓴이 날짜 조회
22-06-20 조회 8,242
09-11 조회 146
09-04 조회 787
08-09 조회 1,647
08-05 조회 2,832
07-30 조회 1,642
07-30 조회 1,545
07-15 조회 2,823
07-01 조회 3,006
06-30 조회 3,000
06-22 조회 3,732
06-17 조회 2,881
06-14 조회 1,619
05-29 조회 1,717
05-16 조회 1,662
05-04 조회 3,158
04-29 조회 3,344
04-28 조회 3,163
04-27 조회 3,130
04-25 조회 2,159
04-24 조회 3,889
04-23 조회 3,282
04-14 조회 2,303
04-08 조회 3,138
04-01 조회 4,843
03-31 조회 3,860
03-16 조회 4,007
03-14 조회 5,175
03-13 조회 4,199
03-10 조회 3,959
03-09 조회 4,090