그누보드에서는 에디터로 첨부한 이미지는 글 삭제시 함께 삭제되지 않고 서버에 남아있습니다.
에디터로 첨부한 이미지가 계속 서버에 남아있게되면 서버의 필요없는 용량을 사용하는 것과 같기 때문에
게시글 삭제시 에디터로 첨부한 이미지도 삭제하도록 되어야 서버의 용량을 줄일 수 있습니다.
에디터로 첨부한 이미지를 삭제하는 방법은 게시글 삭제시 사용되는 함수를 수정하여 삭제하도록 처리 하면되는데
해당 함수는 www/lib/common.lib.php 파일의 delete_editor_thumbnail() 함수입니다.
해당 함수를 아래와 같이 수정하면 에디터로 첨부한 이미지도 삭제되겠습니다.
/* www/lib/common.lib.php */
// 에디터 썸네일 삭제
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);
}
}
}
}