에디터로 올린 이미지 삭제하는 코드 (썸네일도 삭제)
현재 그누보드는 에디터로 첨부한 이미지는 글 삭제시에도 함께 삭제되지 않고 서버에 남아있습니다.
아래 코드를 적용하시면 에디터로 첨부한 이미지가 있는 글을 삭제할 경우 해당 이미지도 삭제하게 됩니다.
/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);
}
}
}
}
댓글 14개
글 작성하면서 에디터를 통해 업로드한 이미지를 다른 게시글에도 사용한 경우
그것을 체크해서 제외하는 로직이 추가되면 좋겠다는 생각을 해봤습니다.
예상컨데 그 상황에서는 지워지지 않을 것 같습니다.
다만 해당 게시물 삭제시 에디터에서 del했던 이미지(게시글에서는 보이지 않지만 서버에 남아있는)도 같이 삭제될 것으로 보입니다.
삭제시 잘 작동이 됩니다.
그러나 글 이동시에도 삭제가 되어버리네요 ㅠㅠ;
글 이동시에는 삭제가 안되었으면 좋겠습니다
게시글 목록
| 번호 | 제목 |
|---|---|
| 23606 | |
| 23598 | |
| 23585 | |
| 23579 | |
| 23578 | |
| 23564 | |
| 23550 | |
| 23549 | |
| 23548 | |
| 23529 | |
| 23510 | |
| 23507 | |
| 23481 | |
| 23471 | |
| 23453 | |
| 23452 | |
| 23450 | |
| 23436 | |
| 23428 | |
| 23404 | |
| 23396 | |
| 23389 | |
| 23380 | |
| 23369 | |
| 23350 | |
| 23337 | |
| 23317 | |
| 23307 | |
| 23298 | |
| 23290 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기