function UploadImageData($POST,$img_data,$modul) {

    global $db,$ar;

    //echo <pre>; print_r($POST); echo </pre>;

    //echo <pre>; print_r($FILES); echo </pre>;

    if(isset($POST[title]) && ($POST[title]!=)) {

        $title=$POST[title];

    } else {

        $title=;

    }

    if(isset($POST[caption]) && ($POST[caption]!=)) {

        $caption=$POST[caption];

    } else {

        $caption=;

    }

    //get last id

    $sql2= select id from `files` order by id desc limit 1;

    $res2=mysqli_query($db,$sql2);

    $r2=mysqli_fetch_assoc($res2);



    if(isset($r2[id]) && ($r2[id]>0)) {

        $iid=$r2[id]+1;

    } else {

        $iid=1;

    }



    //get last seq

    $sql9= select seq from `files` where item_id=.$POST[id]. and modul=.$modul. order by seq desc limit 1;

    $res9=mysqli_query($db,$sql9);

    $r9=mysqli_fetch_assoc($res9);



    if(isset($r9[seq]) && ($r9[seq]>0)) {

        $seq=$r9[seq]+1;

    } else {

        $seq=1;

    }



    $folder_y=$ar[img_path]..$modul./.date(y);

    if (!is_dir($folder_y)) {

        mkdir($folder_y, 0777, true);

    }

    $folder_ym=$folder_y./.date(m);

    if (!is_dir($folder_ym)) {

        mkdir($folder_ym, 0777, true);

    }



    $folder_ymd=$folder_ym./.date(d);

    if (!is_dir($folder_ymd)) {

        mkdir($folder_ymd, 0777, true);

    }



    $folder_ymdh=$folder_ymd./.date(H);

    if (!is_dir($folder_ymdh)) {

        mkdir($folder_ymdh, 0777, true);

    }



    $folder_main=$folder_ymdh./.$POST[id];



    if (!is_dir($folder_main)) {

        mkdir($folder_main, 0777, true);

    }

    $folder_seq=$folder_main./.$seq;

    if (!is_dir($folder_seq)) {

        mkdir($folder_seq, 0777, true);

    }



    $folder_tmp=$folder_seq./tmp;

    if (!is_dir($folder_tmp)) {

        mkdir($folder_tmp, 0777, true);

    }



    /*$sub_folder=$_POST[id]./.$seq./;

    switch($_POST[file_type]) {

      case Image;



    }*/



    $path=date(y)./.date(m)./.date(d)./.date(H)./.$POST[id];;

    $data=$img_data;

    $image_info = getimagesize($img_data);

    $extension = (isset($image_info[mime]) ? explode(/, $image_info[mime] )[1]: );

    $file_name=date(YmdHis)...$extension;



    $data = str_replace(data:image/.$extension.;base64,, , $data);

    $data = str_replace( ,+,$data);

    $bin = base64_decode($data);

    if ($bin === false) {

      //$dt[info]=convert invalid;  

    }

    //$img = imageCreateFromString($bin);

    //tmp file

    $tmp_file=$folder_tmp./.$file_name;

    file_put_contents($tmp_file, $bin);



    $sub_folder=$folder_seq./image;

    $sub_folder_big=$folder_seq./image/big;

    $sub_folder_medium=$folder_seq./image/medium;

    $sub_folder_small=$folder_seq./image/small;



    if(!is_dir($sub_folder)){ mkdir($sub_folder, 0755); }

    if(!is_dir($sub_folder_big)){ mkdir($sub_folder_big, 0755); }

    if(!is_dir($sub_folder_medium)){ mkdir($sub_folder_medium, 0755); }

    if(!is_dir($sub_folder_small)){ mkdir($sub_folder_small, 0755); }



    $source_image=$tmp_file;

    $img_big= $sub_folder_big./.$file_name;

    $img_medium= $sub_folder_medium./.$file_name;

    $img_small= $sub_folder_small./.$file_name;

    //$destination=$ar[img_path]..$img_url;

    //resize(640, $destination, $source_image);

    image_handler($source_image,$img_big,1080,1080,90,false);

    image_handler($source_image,$img_medium,800,800,90,false);

    image_handler($source_image,$img_small,150,150,90,false);



    $udata2=array(

      id=>$iid,

      seq=>$seq,

      modul=>$modul,

      item_id=>$POST[id],

      type=>image,

      title=>gpc($title),

      caption=>gpc($caption),

      url_original=>temp/.$file_name,

      create_at=>time(),

      path=>$path,

      url=>$file_name

      );

    Insert($db,files,$udata2,0);



    $udt2=array(

      img=>$modul./.$path./.$seq./image/small/.$file_name,

    );

    Update($db,$modul,$udt2,id=.$POST[id]);

}