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

정보공유

[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건 2 페이지
번호 제목 글쓴이 날짜 조회
59 7.3 버전 주의사항 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 05-18 14090
58 국가별 국가코드 와 전화번호 코드 배열 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 08-16 20966
57 번호 형식 정규식 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 08-02 17003
56 엑셀파일에서 문자를 복사한뒤 붙여넣기 할경우 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 12-06 23439
55 원하는 날짜에 해당하는 주간날짜 구하기. (월~일) 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 09-06 25331
54 단어변환 참고. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 08-21 22525
53 주민번호로, 생년월일로 나이계산 함수 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 08-02 32061
52 지난주 날짜 구하기 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 05-02 25339
51 PHP 코드최적화 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 04-20 36487
50 의외로 while 문에서 break 사용법을 모르는 사람들이 많네요. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 04-11 23364
49 문서경로 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-27 24030
48 유투브 썸네일 생성을 위한 코드값 추출 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 03-14 27590
47 카텍좌표값 을 WGS84로 변환하기. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 07-11 48306
46 WGS84 두지점 간 거리 계산식. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 07-11 28777
45 get_magic_quotes_gpc 가 on 으로 되어있는경우 해결법. 위토즈쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 04-21 31792