Reference a filename in form validation for an image I am new to Drupal and am making a module to alter a content type. I have a content type that allows a user to submit an email and an image and I want to change the filename of the image to the email before it submits to the database. I figured I can do this in the form validation but I am having trouble finding the right code to access the filename value using $form_state. I am using the form alter hook and adding to the validation.
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);
  }

}