위토즈 - 개발자프로그램판매공간

정보공유

[PHP] 첨부파일 멀티 등록

 

 

<input type="hidden" name="del_cph_ix" id="del_cph_ix" value="" />

<table cellspacing="0" border="1" class="wz_tbl_1" id="wrap-tbl-photos">

    <caption></caption>

    <colgroup>

        <col width="auto"/>

        <col width="80px"/>

        <col width="80px"/>

    </colgroup>

    <thead>

    <tr>

        <th scope="row">첨부파일</th>

        <th scope="row">순서</th>

        <th scope="row"><a href="#none" class="btn_frmline add-tr">추가</a></th>

    </tr>

    </thead>

    <tbody>

    <?php

    if ($cnt_photos > 0) { 

        for ($z = 0; $z < $cnt_photos; $z++) { 

        ?>

        <tr>

            <td>

                <?php

                $sub_file_path = G5_DATA_PATH.'/wzb_plist/sub/'.$arr_photos[$z]['cph_file_name'];

                if (file_exists($sub_file_path) && $arr_photos[$z]['cph_file_name']) {

                    echo '<a href="'.G5_DATA_URL.'/wzb_plist/sub/'.$arr_photos[$z]['cph_file_name'].'" target="_blank" title="원본보기"><img src="'.G5_DATA_URL.'/wzb_plist/sub/'.$arr_photos[$z]['cph_file_name'].'" height="25"></a>';

                }

                ?>

                <input type="hidden" name="cph_ix[]"  value="<?php echo $arr_photos[$z]['cph_ix'];?>">

                <input type="file" name="cph_file[]" value="" class="frm_input" />

            </td>

            <td>

                <input type="text" name="cph_file_sort[]" value="<?php echo $arr_photos[$z]['cph_file_sort'];?>" class="frm_input full_input"  maxlength="10" />

            </td>

            <td class="td_mbstat"><a href="#none" class="btn_frmline del-tr" data-file-ix="<?php echo $arr_photos[$z]['cph_ix'];?>">삭제</a></td>

        </tr>

        <?php

        }

    }

    else {

        ?>

        <tr class="empty">

            <td colspan="3">추가버튼을 클릭해서 부가이미지를 등록해주세요.</td>

        </tr>

        <?php

    }

    ?>

    </tbody>

</table>

 

 

 

 

<script type="text/javascript">

<!--

    jQuery(document).ready(function () {

        $(document).on('click', '.add-tr', function() {

            $('.empty').remove();

            tbl_tr_add();

        });

        $(document).on('click', '.del-tr', function() {

            var cph_ix = $(this).attr('data-file-ix');

            var cph_ix_input = $('#del_cph_ix');

            if (cph_ix) {

                cph_ix_input.val((cph_ix_input.val() ? cph_ix_input.val() + ',' : '') + cph_ix);

            }

            

            $(this).closest('tr').remove();

            var tr_cnt = $('#wrap-tbl-photos tbody tr').length;

            if (tr_cnt == 0) {

                $('#wrap-tbl-photos').append('<tr class="empty"><td colspan="4">추가버튼을 클릭해서 부가이미지를 등록해주세요.</td></tr>');

            }

        });

    });

 

    function tbl_tr_add() {

        

        var tbl_tr_html = '';

            tbl_tr_html += '<tr>';

            tbl_tr_html += '    <td>';

            tbl_tr_html += '    <input type="hidden" name="cph_ix[]"  value="">';

            tbl_tr_html += '    <input type="file" name="cph_file[]" value="" class="frm_input" />';

            tbl_tr_html += '    </td>';

            tbl_tr_html += '    <td>';

            tbl_tr_html += '        <input type="text" name="cph_file_sort[]" value="" class="frm_input full_input"  maxlength="10" />';

            tbl_tr_html += '    </td>';

            tbl_tr_html += '    <td class="td_mbstat"><a href="#none" class="btn_frmline del-tr">삭제</a></td>';

            tbl_tr_html += '</tr>';

 

        $('#wrap-tbl-photos').append(tbl_tr_html);

    }

//-->

</script>

 

 

 

--------------------------------------------------------------

 

submit_ok.php

 

 

 

if ($w == 'd') { 

 

    // 관련 부가이미지 파일 삭제.

    $query = "select * from {테이블명} where cp_ix = '$cp_ix' ";

    $res = sql_query($query);

    while($row = sql_fetch_array($res)) { 

        @unlink(G5_DATA_PATH."/wzb_plist/sub/".$row['cph_file_name']);

    }

    if ($res) sql_free_result($res);

 

    // 삭제    

    $query = "delete from {테이블명} where cp_ix = '{$cp_ix}' ";

    sql_query($query);

 

    $query = "delete from {$g5['wzb_corp_table']} where cp_ix = '{$cp_ix}' ";

    sql_query($query);

 

    goto_url('./wzb_corp_list.php?'.$qstr);

 

 

if ($w == '' || $w == 'u') {

 

    // 부가이미지 정보변경

    $cph_ix = $_POST['cph_ix'];

    if (is_array($cph_ix)) { 

        $cnt_cph_ix = count($cph_ix);

        for ($i=0;$i<$cnt_cph_ix;$i++) { 

            $sql = "update {테이블명} set cph_file_sort = '".$_POST['cph_file_sort'][$i]."' where cph_ix = '".$cph_ix[$i]."' and cp_ix = '$cp_ix' ";

            sql_query($sql);

        } 

    } 

 

    // 부가이미지등록.

    @mkdir(G5_DATA_PATH.'/wzb_plist/sub/', G5_DIR_PERMISSION);

    @chmod(G5_DATA_PATH.'/wzb_plist/sub/', G5_DIR_PERMISSION);

    $sqlCommon = "";

    $file = wz_file_upload(G5_DATA_PATH."/wzb_plist/sub/", (1048576 * 5), "cph_file", "jpg|gif|tiff|png|jpeg|bmp", "edit");

    $cph_file_name = "";

    if (is_array($file)) {

        for ($i=0;$i<count($file);$i++) { 

            $cph_file_name = $file[$i]["filename"];

            $cph_file_name_org = $file[$i]["filename_org"];

            $cph_file_size = $file[$i]["filesize"];

            $cph_file_sort = $file[$i]["filesort"];

            if ($cph_file_name) { 

                $sql = " insert into {테이블명} set 

                                cp_ix = '$cp_ix',

                                cph_file_name = '$cph_file_name', 

                                cph_file_name_org = '$cph_file_name_org', 

                                cph_file_size = '$cph_file_size', 

                                cph_file_sort = '$cph_file_sort'

                                 ";

                sql_query($sql);

            }     

        }

    }

 

    $del_cph_ix = $_POST['del_cph_ix'];

    if ($del_cph_ix) { 

        $arr_cph_ix = array_map('trim', explode(',', $del_cph_ix));

        $cnt_cph_ix = count($arr_cph_ix);

        for ($i=0;$i<$cnt_cph_ix;$i++) { 

            $sql = " select cph_file_name from {테이블명} where cph_ix = '".$arr_cph_ix[$i]."' and cp_ix = '$cp_ix' ";

            $cph = sql_fetch($sql);

            @unlink(G5_DATA_PATH."/wzb_plist/sub/".$cph['cph_file_name']);

 

            $sql = "delete from {테이블명} where cph_ix = '".$arr_cph_ix[$i]."' and cp_ix = '$cp_ix' ";

            sql_query($sql);

        } 

    } 

}

 

 

정보공유
Total 74건 1 페이지
번호 제목 글쓴이 날짜 조회
74 prepare bind_param 쿼리구분 select * 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 08-14 1520
73 stmt 등록 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 06-14 1870
72 prepare 함수 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 05-16 1883
71 [sprintf 함수] 결과값 처리 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-09 3513
70 php json_encode 옵션 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 08-09 3814
69 도메인주소 매칭 확인 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-21 5030
68 Proxy 서버나 로드밸런서 등에서는 HTTPS 접속시 HTTP_X_FORWARDED_PROTO 로 체크해야 하는 경우 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-21 5059
67 날짜 구하기 계산식. 1월 31일은 3월3일로 계산되는 문제 해결. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 02-03 5181
66 휴대폰 번호 여부 체크 확인 함수 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10-21 6499
65 문자 내용이 euc-kr 인지 체크 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 08-01 7774
64 HTTP_X_REQUESTED_WITH 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-29 11234
63 요일 처리 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 01-22 10865
62 다차원 배열 정렬 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 12-14 11990
61 원격지 이미지 파일 저장하고 이미지 파일 아닌경우 삭제 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 12-12 11715
60 정규식 제거 및 특정 태그 제거 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-02 15562