// // 이미지 선택 이벤트 처리 // $("#upfileimage").change(function (e) { // processFiles(this.files, tablename, "image", "upfileimage"); // }); // 파일 업로드 및 처리 함수 function processFiles(files, tablename, item, upfilename) { var num = $("#num").val(); if (!files || files.length === 0) { console.warn("파일이 선택되지 않았습니다."); return; } showMsgModal(3); // 파일처리중 const formData = new FormData(); for (const file of files) { formData.append(upfilename + "[]", file); } // 추가 데이터 설정 formData.append("tablename", tablename); formData.append("item", item); formData.append("upfilename", upfilename); formData.append("folderPath", "uploads"); formData.append("DBtable", "picuploads"); formData.append("num", num); // AJAX 요청 $.ajax({ url: "/filedrive/fileprocess.php", type: "POST", enctype: "multipart/form-data", processData: false, contentType: false, data: formData, success: function (response) { console.log("응답 데이터:", response); let successCount = 0; let errorCount = 0; let errorMessages = []; response.forEach((item) => { if (item.status === "success") { successCount++; } else if (item.status === "error") { errorCount++; errorMessages.push(`파일: ${item.file}, 메시지: ${item.message}`); } }); if (successCount > 0) { Toastify({ text: `${successCount}개의 파일이 성공적으로 업로드되었습니다.`, duration: 2000, close: true, gravity: "top", position: "center", backgroundColor: "#4fbe87", }).showToast(); } if (errorCount > 0) { Toastify({ text: `오류 발생: ${errorCount}개의 파일 업로드 실패\n상세 오류: ${errorMessages.join("\n")}`, duration: 5000, close: true, gravity: "top", position: "center", backgroundColor: "#f44336", }).showToast(); } setTimeout(function () { hideMsgModal(); if (item === "attached") displayFile(); if (item === "image") displayImage(); }, 1000); }, error: function (jqxhr, status, error) { console.error("업로드 실패:", jqxhr, status, error); }, }); } // 파일 불러오기 function displayFile() { fetchFiles(tablename, "attached", "#displayFile"); } // 이미지 불러오기 function displayImage() { fetchFiles(tablename, "image", "#displayImage"); } // 파일/이미지 데이터 가져오기 function fetchFiles(tablename, item, targetSelector) { var tablename = $("#tablename").val(); const params = $("#num").val(); if (!params) { console.error("ID 값이 없습니다. 데이터를 불러올 수 없습니다."); return; } $.ajax({ url: "/filedrive/fileprocess.php", type: "GET", data: { num: params, tablename: tablename, item: item, folderPath: "uploads" }, dataType: "json", success: function (data) { console.log("데이터:", data); $(targetSelector).html(""); // 기존 내용 초기화 if (Array.isArray(data) && data.length > 0) { data.forEach(function (fileData, index) { const realName = fileData.realname || "다운로드 파일"; const link = fileData.link || "#"; const fileId = fileData.fileId || null; if (!fileId) { console.error("fileId가 누락되었습니다. index: " + index, fileData); $(targetSelector).append( "