$upload = wp_upload_dir();
     remove_filter('upload_dir', array('templatemerge', 'letters_upload_dir'));
     if (!isset($movefile['error']) && isset($movefile['file'])) {
         $dir_path = $upload['path'];
         chmod(ConvertDirectoryPath($movefile['file']), 0777);
         $dir_url = $upload['url'];
         $filename = str_replace($dir_path . "/", "", $movefile['file']);
         // echo $filename;exit;
         $filetype = $movefile['type'];
         $file_id = rand();
         $config['meta']['files'][$file_id]['file_id'] = $file_id;
         $config['meta']['files'][$file_id]['filename'] = $filename;
         $config['meta']['files'][$file_id]['dir_path'] = ConvertDirectoryPath($dir_path);
         $config['meta']['files'][$file_id]['dir_url'] = ConvertFileUrl($dir_url);
         $config['meta']['files'][$file_id]['filepath'] = ConvertDirectoryPath($movefile['file']);
         $config['meta']['files'][$file_id]['fileurl'] = ConvertFileUrl($movefile['url']);
         $config['meta']['files'][$file_id]['operator_value'] = trim($_POST['letters_operator_value'][$i]);
         $config['meta']['files'][$file_id]['form_field'] = trim($_POST['form_field'][$i]);
         $config['meta']['files'][$file_id]['operator_value_e'] = trim($_POST['letters_operator_value_e'][$i]);
         $config['meta']['files'][$file_id]['form_field_e'] = trim($_POST['form_field_e'][$i]);
         $config['meta']['files'][$file_id]['operator_value_f'] = trim($_POST['letters_operator_value_f'][$i]);
         $config['meta']['files'][$file_id]['form_field_f'] = trim($_POST['form_field_f'][$i]);
         $config['meta']['files'][$file_id]['enable'] = isset($_POST['letters_enable'][$i]) && $_POST['letters_enable'][$i] == 1 ? 1 : 1;
     }
     //$file_id++;
 }
 if (!empty($config['meta'])) {
     //printp($config['meta']);exit;
     $id = TemplateData::update_letters_data($id, $config["form_id"], $config["is_active"], $config["meta"]);
     ?>
             <div class="updated fade" style="padding:6px"><?php 
function UpdateDocToDb($entry, $file_url, $file_path, $type, $invoice)
{
    $id = 1;
    if (!empty($entry) && !empty($file_url)) {
        $form_id = $entry['form_id'];
        $lead_id = $entry['id'];
        $id = TemplateData::updateDocUrl(ConvertFileUrl($file_url), ConvertDirectoryPath($file_path), $lead_id, $type, $invoice);
    }
    return $id;
}