You are here

function _user_import_file in User Import 7

Same name and namespace in other branches
  1. 8 user_import.admin.inc \_user_import_file()
  2. 5.2 user_import.module \_user_import_file()
  3. 5 user_import.module \_user_import_file()
  4. 6.4 user_import.admin.inc \_user_import_file()
  5. 6.2 user_import.admin.inc \_user_import_file()
  6. 7.3 user_import.admin.inc \_user_import_file()
  7. 7.2 user_import.admin.inc \_user_import_file()
2 calls to _user_import_file()
user_import_add_form_submit in ./user_import.admin.inc
user_import_add_form_validate in ./user_import.admin.inc

File

./user_import.admin.inc, line 790
Provide administration configuration pages to import users.

Code

function _user_import_file($import_id = NULL, $ftp_file_selected = NULL) {
  static $file;
  if (!empty($file)) {
    return $file;
  }

  // File was uploaded through browser.
  if (empty($ftp_file_selected) && empty($import_id)) {

    // Delete record from database management so we don't have duplicates problems.
    db_delete('file_managed')
      ->condition('uri', 'temporary://' . $_FILES['files']['name']['file_upload'])
      ->execute();
    $file = file_save_upload('file_upload', array(
      'file_validate_extensions' => array(
        'csv txt',
      ),
    ), FALSE, FILE_EXISTS_RENAME);
    if (!empty($file)) {
      return $file;
    }
  }

  // File was uploaded by FTP
  if (!empty($ftp_file_selected)) {
    $ftp_files = file_scan_directory('private://user_import/uploads/selectable', '/.*$/', array(
      'key' => 'filename',
    ));
    $file = $ftp_files[$ftp_file_selected];
    $file->filepath = $file->uri;
    return $file;
  }

  // Use file info stored in database
  if (!empty($import_id)) {
    $import = _user_import_settings_select($import_id);
    $file->uri = $import['filepath'];
    $file->filepath = $import['filepath'];
    $file->oldfilename = $import['oldfilename'];
    $file->filename = $import['filename'];
    return $file;
  }
  return;
}