스마트에디터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명이 반응했습니다
|

댓글 1개

감사합니다. ^^

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

댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

+
제목 글쓴이 날짜 조회
3년 전 조회 5,384
6시간 전 조회 30
2일 전 조회 54
2일 전 조회 44
6일 전 조회 90
1주 전 조회 92
1주 전 조회 126
1주 전 조회 197
1주 전 조회 231
1주 전 조회 387
2주 전 조회 495
3주 전 조회 684
3주 전 조회 643
3주 전 조회 612
1개월 전 조회 919
1개월 전 조회 859
1개월 전 조회 830
1개월 전 조회 906
1개월 전 조회 989
1개월 전 조회 985
1개월 전 조회 966
1개월 전 조회 968
2개월 전 조회 1,149
2개월 전 조회 1,136
2개월 전 조회 1,024
2개월 전 조회 970
2개월 전 조회 1,196
2개월 전 조회 1,112
2개월 전 조회 956
2개월 전 조회 1,242
2개월 전 조회 1,197