/home/mjc1/public_html/j3demo/webhard/ajax.file_upload_process.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
include_once("./_common.php");

$b_table $id_cust;
if(
$b_table==''){ $b_table "webhard"; }
$b_idx "1";

$rtn_file_html "";

function 
board_file($b_table$b_idx$files$add_file_del){
    Global 
$j3$table_name$rtn_file_html$_POST;

    
$datetime date("Y-m-d H:i:s",time());
    
$date_dir date("ymd",time());

    function 
realpos_set($b_realpos){
        Global 
$j3

        
$sql "select count(*) as cnt from webhard where b_realpos = '{$b_realpos}' ";
        
$cnt_info sql_fetch($sql,$j3['connect_j3']);

        
$sql "update webhard set b_cnt = '{$cnt_info['cnt']}' where b_realpos = '{$b_realpos}' ";
        
mysql_query($sql,$j3['connect_j3']);    
    }

    foreach(
$files['name'] as $key=>$val){
        if(
$_POST['add_file_del_'.$key]=='1'){ // 삭제 체크시
            //delete_file($b_table, $idx, $key);
        
}
        if(
$val!=''){
            
$val preg_replace("/\.(php|phtm|htm|cgi|pl|exe|jsp|asp|inc)/i""$0-x"$val);

            
$save_name "{$b_table}_{$b_idx}_{$key}_".time();
            
$dest "{$j3['j3_data_path']}/webhard/{$date_dir}/";
            @
mkdir($destG5_DIR_PERMISSION);
            @
chmod($destG5_DIR_PERMISSION);
            
$img_size getimagesize($files['tmp_name'][$key]); 
            
move_uploaded_file($files['tmp_name'][$key],$dest.$save_name);
            @
chmod($dest.$save_nameG5_FILE_PERMISSION);

            
$dir "";
            
$cur_dir $_POST['cur_dir']; $new_dir $_POST['new_dir'];
            if(
$cur_dir=='' && $new_dir!=''){
                
$dir "/".$new_dir;
            }
            if(
$cur_dir!='' && $new_dir==''){
                
$dir "/".$cur_dir;
            }
            if(
$cur_dir!='' && $new_dir!=''){
                
$dir "/".$cur_dir."/".$new_dir;
            }

            
$b_realpos $_SERVER['DOCUMENT_ROOT']."/data/webhard/{$date_dir}/{$save_name}";
            
$sql "insert into webhard set
                        b_table = '
{$b_table}', b_idx = '{$b_idx}', b_no = '{$key}' , b_oriname = '{$val}',
                        b_filename = '
$save_name', b_download = 0, b_filesize = '{$files['size'][$key]}', 
                        b_width = '
{$img_size[0]}', b_height = '{$img_size[1]}', b_regdate = '{$datetime}',
                        b_session_key = '
{$_POST['session_key']}', b_savedir = '{$date_dir}', b_realpos = '{$b_realpos}',
                        b_virt_dir = '
{$dir}'
            "
;
            
mysql_query($sql,$j3['connect_j3']);

            
$idx mysql_insert_id($j3['connect_j3']);

            
realpos_set($b_realpos);

            
$rtn_file_html .= "<p><a href='./file_download.php?idx={$idx}'>$val</a>&nbsp;&nbsp;<a class='file_del_class' data-idx='{$idx}'>[삭제]</a></p>";
        }
    }
}

function 
delete_file($b_table$idx){ // 파일 정보 삭제
    
Global $j3
    
$sql "select * from webhard where idx = {$idx} ";
    
$info sql_fetch($sql,$j3['connect_j3']);
    if(
$info['b_table']!=$b_table){
        return 
$sql."삭제권한이 없습니다.";
    } else {
        
unlink($info['b_realpos']);
        
$sql "delete from webhard where idx = '{$idx}' ";
        
mysql_query($sql,$j3['connect_j3']);    
        return 
"OK";
    }
}


if(
count($_FILES['attach'])>0){
    
board_file($b_table$b_idx,$_FILES['attach'], $add_file_del);
    
$rtn_array['file_html'] = $rtn_file_html;
    echo 
json_encode($rtn_array);
}

if(
$mode=='del' && $idx!=''){
    
$rtn delete_file($b_table,$idx);
    echo 
$rtn;
}
?>