Where does Drupal set the uploaded file name syntax? I have a file with a filename which has a double underscore in it. When Drupal saves the file, it shortens it to be only one. ie:


  Snapshot__john_doe_2_opt.jpg


When Drupal saves the file, it removes one of the underscores and names it this:


  Snapshot_john_doe_2_opt.jpg


Where does Drupal do this? I need to account for any changes which Drupal makes to the filename and I need to know what other characters it may remove etc.
You can use transliteration module.

and in code use code like

function hook_transliteration_clean_filename_prepare_alter(&amp;$filename, $source_langcode) {
  $filename = drupal_strtolower($filename);
  $filename = str_replace('__','_', $filename);
} 


Above code is not tested, Hope it will help you.