현재 그누보드는 에디터로 첨부한 이미지는 글 삭제시에도 함께 삭제되지 않고 서버에 남아있습니다.
아래 코드를 적용하시면 에디터로 첨부한 이미지가 있는 글을 삭제할 경우 해당 이미지도 삭제하게 됩니다.
/lib/common.lib.php 에서 기존
// 에디터 썸네일 삭제
function delete_editor_thumbnail($contents)
함수 내용을 아래와 같이 변경한다.
// 에디터 썸네일 삭제
function delete_editor_thumbnail($contents)
{
if(!$contents)
return;
// $contents 중 img 태그 추출
$matchs = get_editor_image($contents, false);
if(!$matchs)
return;
for($i=0; $i<count($matchs[1]); $i++) {
// 이미지 path 구함
$imgurl = @parse_url($matchs[1][$i]);
if(strpos($imgurl['path'], "/data/") != 0) {
$data_path = preg_replace("/^\/.*\/data/", "/data", $imgurl['path']);
} else {
$data_path = $imgurl['path'];
}
$is_destfile = false;
if(preg_match('/(gif|jpe?g|bmp|png)$/i', strtolower(end(explode('.', $data_path))))){
$destfile = ( ! preg_match('/\w+\/\.\.\//', $data_path) ) ? G5_PATH.$data_path : '';
if($destfile && preg_match('/\/data\/editor\/[A-Za-z0-9_]{1,20}\//', $destfile) && is_file($destfile)) {
$is_destfile = true;
}
}
if($is_destfile) {
//원본파일 삭제
@chmod($destfile, G5_FILE_PERMISSION);
@unlink($destfile);
//썸네일파일 삭제
$files = glob(dirname($destfile).'/thumb-'.preg_replace("/\.[^\.]+$/i", "", basename($imgurl['path'])).'*');
//return $files;
if (is_array($files)) {
foreach($files as $filename)
unlink($filename);
}
}
}
}
'IT' 카테고리의 다른 글
index.php 기본 구문 (0) | 2020.05.19 |
---|---|
그누보드 기초_그누보드 테마의 구조, 상수, 파일 용도 (0) | 2019.11.25 |
그래픽카드 네이밍에 따른 성능 구별법 (0) | 2019.11.14 |
다음카페 팝업 소스 (0) | 2019.10.22 |
개국본 배너 (0) | 2019.10.22 |