Reference a filename in form validation for an image
You can to this in the submit handler to rename the file.

function SUBMIT_HANDLER($form, &amp;$form_state) {

  $node = $form_state['node'];

  global $user;

  // Loop over the uploaded files. Be sure to re-name field_files to the name of 
  // your file field.
  foreach($node-&gt;field_files[LANGUAGE_NONE] as $item) {

    // Load the file object
    $file = file_load($item['fid']);

    // To set the destination first remove the filename from the stream wrapper 
    // URI.
    $destination = str_replace($file-&gt;filename, '', $file-&gt;uri);

    // Modify this line to the name of your group field.
    $group = $node-&gt;field_group[LANGUAGE_NONE][0]['value'];

    // And then append the group, uid and put the filename back on the end.
    $destination .= $group.$user-&gt;uid.$file-&gt;filename;

    // And finally rename the file.
    file_move($file, $destination);
  }

}