한 게시글에 이미지를 여러개 올릴 수 있는 게시판을 만들고 있는데요,
관리상 편의를 위하여 한 게시물의 이미지는 게시물 아이디를 폴더명으로 하여 같이 모아두려고 합니다.
이미지 리사이징을 겸해서 Image클래스를 이용하여 만들고 있는데,
잘 되지 않아 질문드립니다.
이란 콘트롤러 안에 _img_processing이라는 함수를 만들었습니다.
인자중 $mode는 리사이징 여부를, $path는 개시물 아이디를, 그리고 $file은 업로드된 파일 명을 의미하며,
다른 함수내에서 $this->
_img_processing($mode,$path,$file); 로 호출해서 사용하고 있습니다.
경로문제가 아닐까... 하는 생각도 조금 들긴 하지만, 정확히 뭐가 문젠지는 모르겠네요.
살펴보시고 문제점이 보이시면 지적 부탁드립니다.
(혹은 다른 방법을 알려주셔도 좋습니다!)
function _img_processing($mode,$path,$file){
// 경로 설정
$directory = './uploads/products/'.$path;
$thumbDir = './uploads/products/'.$path.'/thumb';
// 오리지널 이미지가 저장될 폴더. 경로가 없으면 새로 만들어 줌
if ( !is_dir($directory) ){
mkdir($directory,0777);
}
// 썸네일 이미지가 저장될 폴더. 경로가 없으면 새로 만들어 줌
if ( !is_dir($thumbDir) ){
mkdir($thumbDir,0777);
}
// 이미지 리사이징 및 폴더 안으로 복사
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/products/'.$file;
$config['new_image'] = $directory;
if ( $mode == 'resize' ) {
$config['maintain_ratio'] = TRUE;
$config['width'] = 800;
$config['height'] = 800;
}
$this->load->library('image_lib',$config);
$this->image_lib->resize();
// 원래 업로드한 파일을 지워줌
chmod($config['source_image'],0777);
delete_files($config['source_image']);
// 썸내일 생성
$config['source_image'] = $directory.'/'.$file;
$config['new_image'] = $thumbDir.'/'.$file;
$config['maintain_ratio'] = TRUE;
$config['width'] = 150;
$config['height'] = 150;
$this->image_lib->initialize($config);
$this->image_lib->resize();
}