동적으로 파일 업로드 폼을 만들어서 db에 저장할 수 있나요..?

동적으로 파일 업로드 폼을 만들어서 db에 저장할 수 있나요..?

QA

동적으로 파일 업로드 폼을 만들어서 db에 저장할 수 있나요..?

본문

추가 버튼을 누르면

파일 업로드 폼이 생성되고 파일을 업로드 하면 db에 저장하는 그런 것도 가능한가요..?

된다면 어떤식으로 해야할까요..?

이 질문에 댓글 쓰기 :

답변 3


<?php
if (empty($_POST) == false) {
    print_r($_POST);
}
if (empty($_FILES) == false) {
    print_r($_FILES);
    // DB process
}
?>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(function () {
    $('form').on('click', '.attach_remove', function () {
        $(this).parent('div').remove();
    });
    $('#file_plus').click(function () {
        var $form = $(this.form);
        var $ctrls = $form.find('#dynamic_ctrls');
        var $files = $form.find('#dynamic_files');
        
        if ($files.length == 0) {
            $files = $('<li id="dynamic_files"></li>');
            $ctrls.before($files);
        }
        $filebox = $('<div></div>');
        var $file = $('<input type="file" name="attaches[]">');
        var $file_remove = ('<input type="button" value="remove" class="attach_remove">');
        $filebox.append($file);
        $filebox.append($file_remove);
        $files.append($filebox);
    });
});
</script>
<form method="post" enctype="multipart/form-data">
    <fieldset>
    <legend>dynamic file upload</legend>
    <ul>
        <li><input type="text" name="foo" value="foo"></li>
        <li><input type="text" name="bar" value="bar"></li>
        <li id="dynamic_ctrls">
            <input type="button" id="file_plus" value="add files">
        </li>
        <li><input type="submit"></li>
    </ul>
    </fieldset>
</form>

네 가능합니다.
영카트 관리자 부분에 상품다중등록하는 부분이 있는데 그 부분을 참고하셔서

엑셀을 csv 컨버젼 해서 db 업로드하는 부분을 참고하셔서 적용하시면 되십니다.

 

엑셀 자체를 업로드 하려면 리더라는 부분을 가져와서 처리하도록 적용이 필요한 부분입니다.

대충... 파일추가 및 삭제 기능을 아래처럼 만든 후에

 


<style>
.my { margin-bottom:5px; }
</style>
<div style="margin-bottom:10px">
    <button type="button" onclick="plusFile()">+</button>
    <button type="button" onclick="minusFile()">-</button>
</div>
<form id="myForm" action="db_upload.php" method="post" enctype="multipart/form-data" >
    <div class="my"><input type="file" name="myfile"><button>보내기</button></div>
</form>
<script>
function plusFile() {
    myForm.insertAdjacentHTML("beforeend", "<div class='my'><input type='file' name='myfile'><button>보내기</button></div>");
}
function minusFile() {
    if (myForm.innerHTML.trim() != "") myForm.lastElementChild.remove();
}
</script>

 

db_upload.php 에서 파일업로드와 db 등록을 같이 해 주는 로직을 짜면 되겠죠.

 

https://wittazzurri.com/editor/html_editor.php 확인해보세요.

 

그런데 db 등록이라는게 애매하네요.

파일이름을 등록하는 건지 파일경로를 등록하는 건지 아니면 파일용량을 등록하는 건지... 

답변을 작성하시기 전에 로그인 해주세요.
전체 0 | RSS
QA 내용 검색
  • 개별 목록 구성 제목 답변작성자조회작성일
  • 질문이 없습니다.

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT