5) { sleep(1); header("Location: /login/login_form.php"); exit; } $title_message = '케이스 결합형태 이미지 관리'; include $_SERVER['DOCUMENT_ROOT'] . '/load_header.php'; $jsonFile = $_SERVER['DOCUMENT_ROOT'] . '/shutterbox/shutterbox.json'; $search_keyword = $_REQUEST['search_keyword'] ?? ''; // JSON 파일이 존재하면 읽어오고, 없으면 빈 배열 생성 $shutterboxData = []; if (file_exists($jsonFile)) { $jsonContent = file_get_contents($jsonFile); $shutterboxData = json_decode($jsonContent, true); if (!is_array($shutterboxData)) { $shutterboxData = []; } } // POST 요청 처리: 추가, 수정, 삭제 if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = isset($_POST['action']) ? $_POST['action'] : ''; $index = isset($_POST['index']) ? intval($_POST['index']) : -1; $box_width = isset($_POST['box_width']) ? trim($_POST['box_width']) : ''; $box_height = isset($_POST['box_height']) ? trim($_POST['box_height']) : ''; $exit_direction = isset($_POST['exit_direction']) ? trim($_POST['exit_direction']) : ''; $rail_width = isset($_POST['rail_width']) ? trim($_POST['rail_width']) : ''; $front_bottom_width = isset($_POST['front_bottom_width']) ? trim($_POST['front_bottom_width']) : ''; $search_keyword = isset($_POST['search_keyword']) ? trim($_POST['search_keyword']) : ''; // 이미지 파일 업로드 처리 (drop 영역 및 일반 파일 input 모두 지원) $imagePath = ''; // 1. drop 영역 처리 if (isset($_FILES['upfile']) && isset($_FILES['upfile']['size'][0]) && $_FILES['upfile']['size'][0] > 0) { $uploadDir = $_SERVER['DOCUMENT_ROOT'] . '/shutterbox/images/'; if (!file_exists($uploadDir)) { mkdir($uploadDir, 0777, true); } $originalName = $_FILES['upfile']['name'][0]; $tmpName = $_FILES['upfile']['tmp_name'][0]; $pathInfo = pathinfo($originalName); $fileName = $pathInfo['filename']; $fileExt = isset($pathInfo['extension']) ? $pathInfo['extension'] : ''; $fileNameSanitized = preg_replace('/[^A-Za-z0-9_\-]/', '_', $fileName); $newFileName = date("Y_m_d_H_i_s") . "_" . $fileNameSanitized; if (!empty($fileExt)) { $newFileName .= "." . $fileExt; } $targetFile = $uploadDir . $newFileName; if (!move_uploaded_file($tmpName, $targetFile)) { echo json_encode(['error' => '파일 업로드 실패']); exit; } $imagePath = '/shutterbox/images/' . $newFileName; // 2. 일반 파일 input 처리 } elseif (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) { $uploadDir = $_SERVER['DOCUMENT_ROOT'] . '/shutterbox/images/'; if (!file_exists($uploadDir)) { mkdir($uploadDir, 0777, true); } $originalName = $_FILES['image']['name']; $tmpName = $_FILES['image']['tmp_name']; $pathInfo = pathinfo($originalName); $fileName = $pathInfo['filename']; $fileExt = isset($pathInfo['extension']) ? $pathInfo['extension'] : ''; $fileNameSanitized = preg_replace('/[^A-Za-z0-9_\-]/', '_', $fileName); $newFileName = date("Y_m_d_H_i_s") . "_" . $fileNameSanitized; if (!empty($fileExt)) { $newFileName .= "." . $fileExt; } $targetFile = $uploadDir . $newFileName; if (!move_uploaded_file($tmpName, $targetFile)) { echo json_encode(['error' => '파일 업로드 실패']); exit; } $imagePath = '/shutterbox/images/' . $newFileName; } // 3. 기존 이미지 사용 if (empty($imagePath) && isset($_POST['existing_image'])) { $imagePath = trim($_POST['existing_image']); } if ($action === 'insert' && !empty($exit_direction)) { // 신규 추가 $shutterboxData[] = array( "box_width" => $box_width ?? '', "box_height" => $box_height ?? '', "search_keyword" => $search_keyword ?? '', "exit_direction" => $exit_direction ?? '', "rail_width" => $rail_width ?? '', "front_bottom_width" => $front_bottom_width ?? '', "image" => $imagePath ?? '' ); } elseif ($action === 'update' && !empty($exit_direction) && $index >= 0 && $index < count($shutterboxData)) { // 수정 $shutterboxData[$index]["box_width"] = $box_width ?? ''; $shutterboxData[$index]["box_height"] = $box_height ?? ''; $shutterboxData[$index]["search_keyword"] = $search_keyword ?? ''; $shutterboxData[$index]["exit_direction"] = $exit_direction ?? ''; $shutterboxData[$index]["rail_width"] = $rail_width ?? ''; $shutterboxData[$index]["front_bottom_width"] = $front_bottom_width ?? ''; if (!empty($imagePath)) { $shutterboxData[$index]["image"] = $imagePath; } } elseif ($action === 'copy' && $index >= 0 && $index < count($shutterboxData)) { // 복사 $originalItem = $shutterboxData[$index]; $newImagePath = ''; // 이미지가 있는 경우 복사 if (!empty($originalItem['image'])) { $originalImagePath = $_SERVER['DOCUMENT_ROOT'] . $originalItem['image']; if (file_exists($originalImagePath)) { $pathInfo = pathinfo($originalImagePath); $fileName = $pathInfo['filename']; $fileExt = isset($pathInfo['extension']) ? $pathInfo['extension'] : ''; $newFileName = $fileName . '_copy'; if (!empty($fileExt)) { $newFileName .= "." . $fileExt; } $newImagePath = $pathInfo['dirname'] . '/' . $newFileName; // 파일 복사 if (copy($originalImagePath, $newImagePath)) { $newImagePath = str_replace($_SERVER['DOCUMENT_ROOT'], '', $newImagePath); } else { $newImagePath = $originalItem['image']; // 복사 실패 시 원본 경로 사용 } } else { $newImagePath = $originalItem['image']; // 원본 파일이 없으면 원본 경로 사용 } } // 새로운 항목 추가 $shutterboxData[] = array( "box_width" => $originalItem['box_width'] ?? '', "box_height" => $originalItem['box_height'] ?? '', "search_keyword" => $originalItem['search_keyword'] ?? '', "exit_direction" => $originalItem['exit_direction'] ?? '', "rail_width" => $originalItem['rail_width'] ?? '', "front_bottom_width" => $originalItem['front_bottom_width'] ?? '', "image" => $newImagePath ); // 복사된 데이터를 폼에 설정하기 위한 변수들 $box_width = $originalItem['box_width'] ?? ''; $box_height = $originalItem['box_height'] ?? ''; $exit_direction = $originalItem['exit_direction'] ?? ''; $rail_width = $originalItem['rail_width'] ?? ''; $front_bottom_width = $originalItem['front_bottom_width'] ?? ''; $search_keyword = $originalItem['search_keyword'] ?? ''; } elseif ($action === 'delete' && $index >= 0 && $index < count($shutterboxData)) { // 삭제 array_splice($shutterboxData, $index, 1); } // JSON 파일에 저장 file_put_contents($jsonFile, json_encode($shutterboxData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); } ?>

크기(가로) 크기(세로) 점검구형태 전면부 밑 레일폭 품목검색어 등록
여기로 사진을 drop or 캡쳐 붙여넣기(ctrl+v)
Image No image!

$item): // 역순으로 돌리는 코드는 아래와 같다. ?> $item): ?>
순번 크기(가로) 크기(세로) 점검구형태 전면부 밑치수 레일폭 품목검색어 이미지 수정/삭제
" alt="이미지" style="max-width:100px;"> 없음
등록된 케이스 이미지 정보가 없습니다.