- 정보공유
[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);
}
}
}