Please check the below code,
$csvs = $this->request->getFiles('importdata');
if ((isset($csvs['name'])) && ($csvs['name'] != '')) {
$uploaderFactory = $this->uploaderFactory->create(['fileId' => 'importdata']);
$uploaderFactory->setAllowedExtensions(['csv', 'xls']);
$uploaderFactory->setAllowRenameFiles(true);
$uploaderFactory->setFilesDispersion(true);
$mediaDirectory = $this->fileSystem->getDirectoryRead(DirectoryList::MEDIA);
$destinationPath = $mediaDirectory->getAbsolutePath('FOLDER_PATH');
$result = $uploaderFactory->save($destinationPath);
if (!$result) {
$this->messageManager->addSuccess(__('File cannot be saved to path: $1', $destinationPath));
$this->_redirect('..path..');
} else {
$imagePath = 'FOLDER_PATH' . $result['file'];
$mediaDirectory = $this->fileSystem->getDirectoryRead(DirectoryList::MEDIA);
$destinationfilePath = $mediaDirectory->getAbsolutePath($imagePath);
$csv_data = $this->csvProcessor->getData($destinationfilePath);
$headerArray = ["name", "sku", "desc"];
$headers = $csv_data[0];
$csvHeaders = false;
if (count(array_intersect($headerArray, $headers)) != count($headerArray)) {
$this->messageManager->addError(__("Invalid Formated File"));
$this->_redirect('...path...');
} else {
$count = 0;
foreach ($csv_data as $importItem) {
if (!$csvHeaders) {
$csvHeaders = $importItem;
continue;
}
$mapArr['name'] = $importItem[array_search('name', $headers)];
$mapArr['sku'] = $importItem[array_search('sku', $headers)];
$mapArr['desc'] = $importItem[array_search('desc', $headers)];
....
....
$count++;
}
$this->messageManager->addSuccess(__('A total of %1 record(s) have been Added.', $count));
}
$this->_redirect('..path...');
}
}
my csv file saved in meida/FOLDER_PATH