테스트 사이트 - 개발 중인 베타 버전입니다

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

dlfpire 2년 전 조회 2,092

추가 버튼을 누르면

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

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

댓글을 작성하려면 로그인이 필요합니다.

답변 3개

채택된 답변
+20 포인트
2년 전

</p>

<p><?php

if (empty($_POST) == false) {

    print_r($_POST);

}

if (empty($_FILES) == false) {

    print_r($_FILES);</p>

<p>    // DB process

}

?></p>

<p><script src="<a href="http://code.jquery.com/jquery-latest.min.js"></script>" target="_blank" rel="noopener noreferrer">http://code.jquery.com/jquery-latest.min.js"></script></a>

<script>

$(function () {

    $('form').on('click', '.attach_remove', function () {

        $(this).parent('div').remove();

    });</p>

<p>    $('#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);

        }</p>

<p>        $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></p>

<p><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></p>

<p>

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

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

 

</p>

<p><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></p>

<p>

 

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

 

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

 

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

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

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

플라이
2년 전

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

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

 

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

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인