5) { sleep(1); header("Location: /login/login_form.php"); exit; } $title_message = '가이드레일 이미지 관리'; include $_SERVER['DOCUMENT_ROOT'] . '/load_header.php'; $jsonFile = $_SERVER['DOCUMENT_ROOT'] . '/guiderail/guiderail.json'; $model_name = $_REQUEST['model_name'] ?? ''; // JSON 파일이 존재하면 읽어오고, 없으면 빈 배열 생성 $guiderailData = []; if (file_exists($jsonFile)) { $jsonContent = file_get_contents($jsonFile); $guiderailData = json_decode($jsonContent, true); if (!is_array($guiderailData)) { $guiderailData = []; } } // POST 요청 처리: 추가, 수정, 삭제 if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = isset($_POST['action']) ? $_POST['action'] : ''; $index = isset($_POST['index']) ? intval($_POST['index']) : -1; $firstitem = isset($_POST['firstitem']) ? trim($_POST['firstitem']) : ''; $UA = isset($_POST['UA']) ? trim($_POST['UA']) : ''; $model_name = isset($_POST['model_name']) ? trim($_POST['model_name']) : ''; $check_type = isset($_POST['check_type']) ? trim($_POST['check_type']) : ''; $finishing_type = isset($_POST['finishing_type']) ? trim($_POST['finishing_type']) : ''; $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'] . '/guiderail/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 = '/guiderail/images/' . $newFileName; // 2. 일반 파일 input 처리 } elseif (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) { $uploadDir = $_SERVER['DOCUMENT_ROOT'] . '/guiderail/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 = '/guiderail/images/' . $newFileName; } // 3. 기존 이미지 사용 if (empty($imagePath) && isset($_POST['existing_image'])) { $imagePath = trim($_POST['existing_image']); } if ($action === 'insert' && !empty($model_name)) { // 신규 추가 $guiderailData[] = array( "firstitem" => $firstitem ?? '', "UA" => $UA ?? '', "model_name" => $model_name ?? '', "check_type" => $check_type ?? '', "finishing_type" => $finishing_type ?? '', "search_keyword" => $search_keyword ?? '', "image" => $imagePath ?? '' ); } elseif ($action === 'update' && !empty($model_name) && $index >= 0 && $index < count($guiderailData)) { // 수정 $guiderailData[$index]["firstitem"] = $firstitem ?? ''; $guiderailData[$index]["UA"] = $UA ?? ''; $guiderailData[$index]["model_name"] = $model_name ?? ''; $guiderailData[$index]["check_type"] = $check_type ?? ''; $guiderailData[$index]["finishing_type"] = $finishing_type ?? ''; $guiderailData[$index]["search_keyword"] = $search_keyword ?? ''; if (!empty($imagePath)) { $guiderailData[$index]["image"] = $imagePath; } } elseif ($action === 'delete' && $index >= 0 && $index < count($guiderailData)) { // 삭제 array_splice($guiderailData, $index, 1); } // JSON 파일에 저장 file_put_contents($jsonFile, json_encode($guiderailData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); } ?>

대분류 인정/비인정 제품모델 유형 마감형태 품목검색어 등록
여기로 사진을 drop or 캡쳐 붙여넣기(ctrl+v)
Image No image!

$item): // 역순으로 돌리는 코드는 아래와 같다. ?> $item): ?>
순번 대분류 인정/비인정 모델명 유형 마감 품목검색어 이미지 수정/삭제
" alt="이미지" style="max-width:100px;"> 없음
등록된 가이드레일 이미지 정보가 없습니다.