How to use function like 'rtrim' in drupal?
Use the Drupal file API to do this; file_move() will take care of renaming.

  $file = file_load($fid);
  $new_file_uri = preg_replace('/\\.([a-zA-Z]+)$/', '', $file-&gt;uri); //Remove .whatever from the file name
  file_move($file, $new_file_uri);