You are here

function transliteration_init in Transliteration 6.3

Same name and namespace in other branches
  1. 6 transliteration.module \transliteration_init()
  2. 6.2 transliteration.module \transliteration_init()
  3. 7.3 transliteration.module \transliteration_init()

Implementation of hook_init().

Sanitize file names during upload.

File

./transliteration.module, line 157
Converts non-latin text to US-ASCII and sanitizes file names.

Code

function transliteration_init() {
  if (!empty($_FILES['files']) && variable_get('transliteration_file_uploads', TRUE)) {

    // Figure out language, which is available in $_POST['language'] for node
    // forms.
    $langcode = NULL;
    if (!empty($_POST['language'])) {
      $languages = language_list();
      if (isset($languages[$_POST['language']])) {
        $langcode = $_POST['language'];
      }
    }
    foreach ($_FILES['files']['name'] as $field => $filename) {

      // Keep a copy of the unaltered file name.
      $_FILES['files']['orig_name'][$field] = $filename;
      $_FILES['files']['name'][$field] = transliteration_clean_filename($filename, $langcode);
    }
  }
}