private function handleUpload(FormInterface $form, DirectoryInterface $directory)
    {
        /** @var UploadedFile[] $files */
        $files = $form->get('select')->getData();
        $permissions = $this->app['filepermissions'];

        foreach ($files as $fileToProcess) {
            $fileToProcess = [
                'name'     => $fileToProcess->getClientOriginalName(),
                'tmp_name' => $fileToProcess->getPathname(),
            ];

            $originalFilename = $fileToProcess['name'];
            $filename = basename($originalFilename);
            $filename = $this->app['upload.sanitizer']->slugify($filename, $this->app['config']->get('general/upload/replacement', '-'));

            try {
                $isAllowed = $permissions->allowedUpload($filename);
            } catch (IOException $e) {
                $this->flashes()->error($e->getMessage());

                continue;
            }

            if ($isAllowed) {
                $this->processUpload($directory, $filename, $fileToProcess);
            } else {
                $extensionList = [];
                foreach ($permissions->getAllowedUploadExtensions() as $extension) {
                    $extensionList[] = '<code>.' . htmlspecialchars($extension, ENT_QUOTES) . '</code>';
                }
                $extensionList = implode(' ', $extensionList);
                $this->flashes()->error(
                    Trans::__("File '%file%' could not be uploaded (wrong/disallowed file type). Make sure the file extension is one of the following:", ['%file%' => $filename])
                    . $extensionList
                );
            }
        }
    }