You are here

function filefield_sources_clean_filename in FileField Sources 6

Same name and namespace in other branches
  1. 8 filefield_sources.module \filefield_sources_clean_filename()
  2. 7 filefield_sources.module \filefield_sources_clean_filename()

Clean up the file name, munging extensions and transliterating.

Parameters

$filepath: A string containing a file name or full path. Only the file name will actually be modified.

Return value

A file path with a cleaned-up file name.

2 calls to filefield_sources_clean_filename()
filefield_source_attach_value in sources/attach.inc
A #filefield_value_callback function.
filefield_source_remote_value in sources/remote.inc
A #filefield_value_callback function.

File

./filefield_sources.module, line 333
Extend FileField to allow files from multiple sources.

Code

function filefield_sources_clean_filename($filepath) {
  global $user;
  $filename = basename($filepath);
  if (module_exists('transliteration')) {
    module_load_include('inc', 'transliteration');
    $langcode = NULL;
    if (!empty($_POST['language'])) {
      $languages = language_list();
      $langcode = isset($languages[$_POST['language']]) ? $_POST['language'] : NULL;
    }
    $filename = transliteration_clean_filename($filename, $langcode);
  }

  // Because this transfer mechanism does not use file_save_upload(), we need
  // to manually munge the filename to prevent dangerous extensions.
  // See file_save_upload().
  $extensions = '';
  foreach ($user->roles as $rid => $name) {
    $extensions .= ' ' . variable_get("upload_extensions_{$rid}", variable_get('upload_extensions_default', 'jpg jpeg gif png txt html doc xls pdf ppt pps odt ods odp'));
  }
  $filename = file_munge_filename($filename, $extensions);
  $directory = dirname($filepath);
  return ($directory ? $directory . '/' : $directory) . $filename;
}