filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT); $directory->create(self::TARGET_DIRECTORY); $uploader = $this->uploaderFactory->create(['fileId' => $fileId]); $uploader->setAllowedExtensions(['xlsx', 'xls']); $uploader->setAllowRenameFiles(true); $uploader->setFilesDispersion(false); $result = $uploader->save($directory->getAbsolutePath(self::TARGET_DIRECTORY)); if (!$result || empty($result['path']) || empty($result['file'])) { throw new LocalizedException(__('The Excel file could not be uploaded.')); } return rtrim((string)$result['path'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim((string)$result['file'], DIRECTORY_SEPARATOR); } }