diff --git a/app/Controllers/Admin/BoardController.php b/app/Controllers/Admin/BoardController.php index 7f005a2..a3f1b89 100644 --- a/app/Controllers/Admin/BoardController.php +++ b/app/Controllers/Admin/BoardController.php @@ -49,7 +49,7 @@ class BoardController extends AdminController $this->_viewDatas['fieldDatas']['confirmpassword'] = $this->request->getVar('confirmpassword'); break; case 'board_file': - $this->_viewDatas['fieldDatas'][$field] = $this->single_upload_procedure($field, $entity); + $this->_viewDatas['fieldDatas'][$field] = $this->upload_file_procedure($field); break; default: return parent::getFieldFormData($field, $entity); diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 9ddfc0b..5f95ac9 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -95,8 +95,11 @@ abstract class BaseController extends Controller } //Upload FIle관련 - protected function upload_file_process(UploadedFile $upfile) + private function upload_file_process(UploadedFile $upfile) { + if (!is_dir(WRITEPATH . PATHS['UPLOAD'])) { + mkdir(WRITEPATH . PATHS['UPLOAD'], 0640); + } $fileName = null; if ($upfile->isValid() && !$upfile->hasMoved()) { $originName = $upfile->getName(); @@ -106,13 +109,34 @@ abstract class BaseController extends Controller } return $fileName; } - protected function single_upload_procedure(string $field, $entity = null) + private function upload_image_process(UploadedFile $upfile, $sizeX = 100, $sizeY = 100) { - if ($upfile = $this->request->getFile($field)) { - return $this->upload_file_process($upfile); + if (!is_dir(FCPATH . '/upload_images')) { + mkdir(FCPATH . '/upload_images', 0640); } + //참고:https://www.positronx.io/codeigniter-resize-image-with-image-manipulation-tutorial/ + $fileName = null; + if ($upfile->isValid() && !$upfile->hasMoved()) { + $originName = $upfile->getName(); + $fileName = $upfile->getRandomName(); + $image = \Config\Services::image(); + $image->withFile($upfile) + ->resize($sizeX, $sizeY, true, 'height') + ->save(FCPATH . '/upload_images/' . $fileName); + $upfile->move(FCPATH . '/upload_images/', $fileName . "_original"); + $fileName = $originName . DEFAULTS['DELIMITER_FILE'] . $fileName; + } + return $fileName; } - protected function multiple_upload_procedure(string $field, $entity = null): array + protected function upload_file_procedure(string $field) + { + return $this->upload_file_process($this->request->getFile($field)); + } + protected function upload_photo_procedure(string $field, $sizeX = 100, $sizeY = 100) + { + return $this->upload_image_process($this->request->getFile($field), $sizeX, $sizeY); + } + protected function upload_multiple_file_process(string $field): array { //Multiple파일의경우 html에서는 필드명[]를 넣어야하며 //rule에서 "uploaded[필드명.0]|is_image[필드명]~~" 이런식으로 넣어야함 @@ -276,8 +300,6 @@ abstract class BaseController extends Controller { $titleField = $this->_model->getTitleField(); $entity->$titleField = "RE: " . $entity->$titleField; - $contentField = $this->_model->getContentField(); - $entity->$contentField .= "\n----------------------------------------------\n"; $this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []]; return $entity; } diff --git a/app/Controllers/Front/BoardController.php b/app/Controllers/Front/BoardController.php index 1242743..6023378 100644 --- a/app/Controllers/Front/BoardController.php +++ b/app/Controllers/Front/BoardController.php @@ -50,7 +50,7 @@ class BoardController extends FrontController $this->_viewDatas['fieldDatas']['confirmpassword'] = $this->request->getVar('confirmpassword'); break; case 'board_file': - $this->_viewDatas['fieldDatas'][$field] = $this->single_upload_procedure($field, $entity); + $this->_viewDatas['fieldDatas'][$field] = $this->upload_file_procedure($field); break; default: return parent::getFieldFormData($field, $entity);