requireAuth(); if ($auth instanceof ResponseInterface) { return $auth; } $file = $this->request->getFile('file'); if (!$file) { return $this->respondError('파일이 전송되지 않았습니다.'); } if (!$file->isValid()) { return $this->respondError('유효하지 않은 파일입니다.'); } // Generate unique filename $newName = $file->getRandomName(); $uploadPath = FCPATH . 'uploads/files/'; // Create directory if not exists if (!is_dir($uploadPath)) { mkdir($uploadPath, 0755, true); } try { $file->move($uploadPath, $newName); $fileData = [ 'name' => $file->getClientName(), 'url' => '/uploads/files/' . $newName, 'path' => $uploadPath . $newName, 'size' => $file->getSize(), 'type' => $file->getClientMimeType() ]; return $this->respondSuccess($fileData, '파일 업로드 성공'); } catch (\Exception $e) { return $this->respondError('파일 업로드 중 오류가 발생했습니다: ' . $e->getMessage()); } } /** * Upload image */ public function uploadImage() { $auth = $this->requireAuth(); if ($auth instanceof ResponseInterface) { return $auth; } $file = $this->request->getFile('file'); if (!$file) { return $this->respondError('이미지가 전송되지 않았습니다.'); } if (!$file->isValid()) { return $this->respondError('유효하지 않은 이미지입니다.'); } // Validate image type $allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/webp']; if (!in_array($file->getClientMimeType(), $allowedTypes)) { return $this->respondError('허용되지 않는 이미지 형식입니다.'); } // Generate unique filename $newName = $file->getRandomName(); $uploadPath = FCPATH . 'uploads/images/'; // Create directory if not exists if (!is_dir($uploadPath)) { mkdir($uploadPath, 0755, true); } try { $file->move($uploadPath, $newName); // Optional: Resize image // $image = \Config\Services::image() // ->withFile($uploadPath . $newName) // ->resize(800, 800, true, 'height') // ->save($uploadPath . $newName); $imageData = [ 'name' => $file->getClientName(), 'url' => '/uploads/images/' . $newName, 'path' => $uploadPath . $newName, 'size' => $file->getSize(), 'type' => $file->getClientMimeType() ]; return $this->respondSuccess($imageData, '이미지 업로드 성공'); } catch (\Exception $e) { return $this->respondError('이미지 업로드 중 오류가 발생했습니다: ' . $e->getMessage()); } } /** * Upload staff image (영업사원 이미지) */ public function uploadStaffImage() { $auth = $this->requireAuth(); if ($auth instanceof ResponseInterface) { return $auth; } $file = $this->request->getFile('file'); if (!$file) { return $this->respondError('이미지가 전송되지 않았습니다.'); } if (!$file->isValid()) { return $this->respondError('유효하지 않은 이미지입니다.'); } // Validate image type $allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/webp']; if (!in_array($file->getClientMimeType(), $allowedTypes)) { return $this->respondError('허용되지 않는 이미지 형식입니다.'); } // Generate unique filename $newName = $file->getRandomName(); $uploadPath = FCPATH . 'uploads/staff/'; // Create directory if not exists if (!is_dir($uploadPath)) { mkdir($uploadPath, 0755, true); } try { $file->move($uploadPath, $newName); $imageData = [ 'name' => $file->getClientName(), 'url' => '/uploads/staff/' . $newName, 'path' => $uploadPath . $newName, 'size' => $file->getSize(), 'type' => $file->getClientMimeType() ]; return $this->respondSuccess($imageData, '직원 이미지 업로드 성공'); } catch (\Exception $e) { return $this->respondError('이미지 업로드 중 오류가 발생했습니다: ' . $e->getMessage()); } } /** * Upload advisor image (어드바이저 이미지) */ public function uploadAdvisorImage() { $auth = $this->requireAuth(); if ($auth instanceof ResponseInterface) { return $auth; } $file = $this->request->getFile('file'); if (!$file) { return $this->respondError('이미지가 전송되지 않았습니다.'); } if (!$file->isValid()) { return $this->respondError('유효하지 않은 이미지입니다.'); } // Validate image type $allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/webp']; if (!in_array($file->getClientMimeType(), $allowedTypes)) { return $this->respondError('허용되지 않는 이미지 형식입니다.'); } // Generate unique filename $newName = $file->getRandomName(); $uploadPath = FCPATH . 'uploads/advisor/'; // Create directory if not exists if (!is_dir($uploadPath)) { mkdir($uploadPath, 0755, true); } try { $file->move($uploadPath, $newName); $imageData = [ 'name' => $file->getClientName(), 'url' => '/uploads/advisor/' . $newName, 'path' => $uploadPath . $newName, 'size' => $file->getSize(), 'type' => $file->getClientMimeType() ]; return $this->respondSuccess($imageData, '어드바이저 이미지 업로드 성공'); } catch (\Exception $e) { return $this->respondError('이미지 업로드 중 오류가 발생했습니다: ' . $e->getMessage()); } } /** * Upload board file (게시판 파일) */ public function uploadBoardFile() { $auth = $this->requireAuth(); if ($auth instanceof ResponseInterface) { return $auth; } $file = $this->request->getFile('file'); if (!$file) { return $this->respondError('파일이 전송되지 않았습니다.'); } if (!$file->isValid()) { return $this->respondError('유효하지 않은 파일입니다.'); } // Generate unique filename $newName = $file->getRandomName(); $uploadPath = FCPATH . 'uploads/bbs/'; // Create directory if not exists if (!is_dir($uploadPath)) { mkdir($uploadPath, 0755, true); } try { $file->move($uploadPath, $newName); $fileData = [ 'name' => $file->getClientName(), 'url' => '/uploads/bbs/' . $newName, 'path' => $uploadPath . $newName, 'size' => $file->getSize(), 'type' => $file->getClientMimeType() ]; return $this->respondSuccess($fileData, '게시판 파일 업로드 성공'); } catch (\Exception $e) { return $this->respondError('파일 업로드 중 오류가 발생했습니다: ' . $e->getMessage()); } } /** * Upload event file (이벤트 게시판 파일) */ public function uploadEventFile() { $auth = $this->requireAuth(); if ($auth instanceof ResponseInterface) { return $auth; } $file = $this->request->getFile('file'); if (!$file) { return $this->respondError('파일이 전송되지 않았습니다.'); } if (!$file->isValid()) { return $this->respondError('유효하지 않은 파일입니다.'); } // Generate unique filename $newName = $file->getRandomName(); $uploadPath = FCPATH . 'uploads/bbs/event/'; // Create directory if not exists if (!is_dir($uploadPath)) { mkdir($uploadPath, 0755, true); } try { $file->move($uploadPath, $newName); $fileData = [ 'name' => $file->getClientName(), 'url' => '/uploads/bbs/event/' . $newName, 'path' => $uploadPath . $newName, 'size' => $file->getSize(), 'type' => $file->getClientMimeType() ]; return $this->respondSuccess($fileData, '이벤트 파일 업로드 성공'); } catch (\Exception $e) { return $this->respondError('파일 업로드 중 오류가 발생했습니다: ' . $e->getMessage()); } } /** * Upload news file (뉴스 게시판 파일) */ public function uploadNewsFile() { $auth = $this->requireAuth(); if ($auth instanceof ResponseInterface) { return $auth; } $file = $this->request->getFile('file'); if (!$file) { return $this->respondError('파일이 전송되지 않았습니다.'); } if (!$file->isValid()) { return $this->respondError('유효하지 않은 파일입니다.'); } // Generate unique filename $newName = $file->getRandomName(); $uploadPath = FCPATH . 'uploads/bbs/news/'; // Create directory if not exists if (!is_dir($uploadPath)) { mkdir($uploadPath, 0755, true); } try { $file->move($uploadPath, $newName); $fileData = [ 'name' => $file->getClientName(), 'url' => '/uploads/bbs/news/' . $newName, 'path' => $uploadPath . $newName, 'size' => $file->getSize(), 'type' => $file->getClientMimeType() ]; return $this->respondSuccess($fileData, '뉴스 파일 업로드 성공'); } catch (\Exception $e) { return $this->respondError('파일 업로드 중 오류가 발생했습니다: ' . $e->getMessage()); } } /** * Upload branch manager image (지점장 이미지) */ public function uploadBManagerImage() { $auth = $this->requireAuth(); if ($auth instanceof ResponseInterface) { return $auth; } $file = $this->request->getFile('file'); if (!$file) { return $this->respondError('이미지가 전송되지 않았습니다.'); } if (!$file->isValid()) { return $this->respondError('유효하지 않은 이미지입니다.'); } // Validate image type $allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'image/webp']; if (!in_array($file->getClientMimeType(), $allowedTypes)) { return $this->respondError('허용되지 않는 이미지 형식입니다.'); } // Generate unique filename $newName = $file->getRandomName(); $uploadPath = FCPATH . 'uploads/bmanager/'; // Create directory if not exists if (!is_dir($uploadPath)) { mkdir($uploadPath, 0755, true); } try { $file->move($uploadPath, $newName); $imageData = [ 'name' => $file->getClientName(), 'url' => '/uploads/bmanager/' . $newName, 'path' => $uploadPath . $newName, 'size' => $file->getSize(), 'type' => $file->getClientMimeType() ]; return $this->respondSuccess($imageData, '지점장 이미지 업로드 성공'); } catch (\Exception $e) { return $this->respondError('이미지 업로드 중 오류가 발생했습니다: ' . $e->getMessage()); } } }