공지사항 파일업로드 수정
Some checks failed
Close Pull Request / main (pull_request_target) Has been cancelled

This commit is contained in:
yangsh
2025-12-30 16:40:40 +09:00
parent fda9b9ab59
commit 38444fcb4f
13 changed files with 89 additions and 7 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Controllers\board;
use App\Controllers\BaseController;
use App\Libraries\MyUpload;
use App\Models\board\NoticeModel;
class Notice extends BaseController
@@ -108,7 +109,7 @@ class Notice extends BaseController
// 공지사항 작성
public function actWrite()
{
$lib = new MyUpload();
try {
@@ -125,6 +126,37 @@ class Notice extends BaseController
$file = $this->request->getFile('file');
if ($file && $file->isValid() && !$file->hasMoved()) {
$uploadPath = "/upload/notice/" . date('Ymd') . "/";
$arrUploadfile = [];
if ($file->isValid() && !$file->hasMoved()) {
$uploadData = $lib->do_upload2($file, $uploadPath);
if ($uploadData !== false) {
$arrUploadfile[] = $uploadData;
}
}
if (!empty($arrUploadfile)) {
foreach ($arrUploadfile as $key => $uploadFile) {
$data['file'] = [
'file_sq' => $this->request->getPost('file_sq'),
'orig_name' => $uploadFile['origin_name'],
'new_name' => $uploadFile['file_name'],
'file_path' => $uploadPath, // 필요에 따라 상대경로로만 저장
'ext' => '.' . $uploadFile['ext'],
'size' => $file->getSize(),
'img_yn' => null,
// 높이/폭은 나중에 getimagesize 등으로 구해도 됨
'img_height' => null,
'img_width' => null,
];
}
}
/*
$origName = $file->getClientName();
$ext = $file->getClientExtension();
$size = $file->getSize();
@@ -154,6 +186,8 @@ class Notice extends BaseController
'img_height' => null,
'img_width' => null,
];
*/
}
@@ -201,6 +235,8 @@ class Notice extends BaseController
// 공지사항 수정요청
public function actModify()
{
$lib = new MyUpload();
try {
$data = [
@@ -216,6 +252,36 @@ class Notice extends BaseController
$file = $this->request->getFile('file');
if ($file && $file->isValid() && !$file->hasMoved()) {
$uploadPath = "/upload/notice/" . date('Ymd') . "/";
$arrUploadfile = [];
if ($file->isValid() && !$file->hasMoved()) {
$uploadData = $lib->do_upload2($file, $uploadPath);
if ($uploadData !== false) {
$arrUploadfile[] = $uploadData;
}
}
if (!empty($arrUploadfile)) {
foreach ($arrUploadfile as $key => $uploadFile) {
$data['file'] = [
'file_sq' => $this->request->getPost('file_sq'),
'orig_name' => $uploadFile['origin_name'],
'new_name' => $uploadFile['file_name'],
'file_path' => $uploadPath, // 필요에 따라 상대경로로만 저장
'ext' => '.' . $uploadFile['ext'],
'size' => $file->getSize(),
'img_yn' => null,
// 높이/폭은 나중에 getimagesize 등으로 구해도 됨
'img_height' => null,
'img_width' => null,
];
}
}
/*
$origName = $file->getClientName();
$ext = $file->getClientExtension();
$size = $file->getSize();
@@ -247,6 +313,8 @@ class Notice extends BaseController
'img_height' => null,
'img_width' => null,
];
*/
}

View File

@@ -101,7 +101,7 @@ class NoticeModel extends Model
$query = $this->db->query($sql, [$id]);
$notice = $query->getRowArray();
$sql = "SELECT bbs_sq, file_sq, file_name, file_path, file_ext, file_size, img_yn, img_height, img_width, orig_name FROM bbs_file_notice WHERE bbs_sq = ?" .
$sql = "SELECT bbs_sq, file_sq, file_name, file_path, file_ext, file_size, img_yn, img_height, img_width, orig_name, cloud_upload_yn FROM bbs_file_notice WHERE bbs_sq = ?" .
" and use_yn = 'Y'";
$query = $this->db->query($sql, [$id]);
$files = $query->getRowArray();
@@ -152,7 +152,7 @@ class NoticeModel extends Model
$f = $data['file'];
$sql = "INSERT INTO bbs_file_notice
(bbs_sq, file_name, file_path, file_ext, file_size, img_yn, img_height, img_width, orig_name)
(bbs_sq, file_name, file_path, file_ext, file_size, img_yn, img_height, img_width, orig_name, cloud_upload_yn)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
$this->db->query($sql, [
@@ -165,6 +165,7 @@ class NoticeModel extends Model
$f['img_height'] ?? null,
$f['img_width'] ?? null,
$f['orig_name'] ?? '',
'Y'
]);
}
@@ -201,7 +202,7 @@ class NoticeModel extends Model
if (empty($f['file_sq'])) {
$sql = "INSERT INTO bbs_file_notice
(bbs_sq, file_name, file_path, file_ext, file_size, img_yn, img_height, img_width, orig_name)
(bbs_sq, file_name, file_path, file_ext, file_size, img_yn, img_height, img_width, orig_name, cloud_upload_yn)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
$this->db->query($sql, [
@@ -214,6 +215,7 @@ class NoticeModel extends Model
$f['img_height'] ?? null,
$f['img_width'] ?? null,
$f['orig_name'] ?? '',
'Y'
]);
} else {
$sql = "UPDATE bbs_file_notice SET

View File

@@ -101,6 +101,11 @@
// 3. 끝 슬래시 정리
$path = rtrim($path, '/');
switch ($path) {
case "/board/notice/write":
case "/board/notice/modify":
case "/board/notice/detail":
$path = "/board/notice/lists";
break;
case "/article/apt/detail":
$path = "/article/apt/lists";
break;

View File

@@ -33,9 +33,16 @@
<th>첨부파일</th>
<td colspan="5" style="min-height: 200px;">
<div>
<a href="<?= site_url('/board/notice/download/' . $files['file_sq']) ?>">
<?= esc($files['orig_name']) ?>
</a>
<?php if ($files['cloud_upload_yn'] === "Y"): ?>
<?php $link = NCLOUD_OBJECT_STORAGE_URL . $files['file_path'] . $files['file_name']; ?>
<a href="<?= $link ?>" download="<?= $files['orig_name'] ?>">
<?= esc($files['orig_name']) ?>
</a>
<?php else: ?>
<a href="<?= site_url('/board/notice/download/' . $files['file_sq']) ?>">
<?= esc($files['orig_name']) ?>
</a>
<?php endif; ?>
</div>
</td>
</tr>