This function is a helper function which dispatches pre upload event.

@param FileInterface $uploaded the uploaded file
@param ResponseInterface $response a response object
@param Request $request the request object
324688
protected function dispatchPreUploadEvent(FileInterface $uploaded, ResponseInterface $response, Request $request)
    {
        $dispatcher = $this->container->get('event_dispatcher');

        // dispatch pre upload event (both the specific and the general)
        $preUploadEvent = new PreUploadEvent($uploaded, $response, $request, $this->type, $this->config);
        $dispatcher->dispatch(UploadEvents::PRE_UPLOAD, $preUploadEvent);
        $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::PRE_UPLOAD, $this->type), $preUploadEvent);
    }
163340
private function handleRedirect(ResponseInterface $response): ResponseInterface
    {
        if ($this->debugbar->isDataPersisted() || session_status() === PHP_SESSION_ACTIVE) {
            $this->debugbar->stackData();
        }

        return $response;
    }
1020315
public function beforeSave(Event $event, EntityInterface $entity) {
		if (!$this->_isFileUploadPresent($entity)) {
			$event->stopPropagation();

			return;
		}

		$this->_checkEntityBeforeSave($entity);

		$this->dispatchEvent('FileStorage.beforeSave', [
			'entity' => $entity,
			'storageAdapter' => $this->getStorageAdapter($entity->get('adapter'))
		], $this->_table);
	}
1213154
protected function onSetUploadedFile(
        /** @noinspection PhpUnusedParameterInspection */
        UploadedFileInterface $uploadedFile = null
    ): void {
        if ($this->isEmpty() && $this->isRequired()) {
            $this->setError('Missing file');
        }
    }
451892
public function applyRequestHeaders(RequestInterface $request)
    {
        if ($this->files || $this->forceMultipart) {
            $request->setHeader(
                'Content-Type',
                'multipart/form-data; boundary=' . $this->getBody()->getBoundary()
            );
        } elseif ($this->fields && !$request->hasHeader('Content-Type')) {
            $request->setHeader(
                'Content-Type',
                'application/x-www-form-urlencoded'
            );
        }

        if ($size = $this->getSize()) {
            $request->setHeader('Content-Length', $size);
        }
    }
35682
private function sendErrorDocument(
        ResponseInterface $response): ResponseInterface
        {
        if ($this->errorDocument && preg_match(
                "/^(4|5){1}[0-2]{1}[0-9]{1}$/", $response->getStatusCode())
            ) {
            $this->errorDocument = str_replace(
                "{status}", $response->getStatusCode(), $this->errorDocument
            );
            if ($this->errorDocument !== filter_input(INPUT_SERVER, "REQUEST_URI")) {
                $response = $response->withHeader(
                    Response::HEADER_REFRESH,
                    "0; " . $this->errorDocument
                );
            }
        }
        return $response;
    }
364950
def set_uploaded(self, files_uploaded):
        
        self.files_uploaded = files_uploaded
        self.__record_progress(Status.UPLOAD_CHANNEL)
159211
private function doRequestUpload(UploadedFile $file)
    {
        $tmpDirectory = $this->getApplication()->getTemporaryDir();
        $data = [];

        if (null !== $file) {
            if ($file->isValid()) {
                if ($file->getClientSize() <= $file->getMaxFilesize()) {
                    $data = $this->buildData($file->getClientOriginalName(), $file->guessExtension());
                    $file->move($tmpDirectory, $data['filename']);
                    $data['size'] = round($file->getClientSize() / 1024, 2);
                    if ($imageInfo = @getimagesize( $data['path'])) {
                        if (isset($imageInfo[0]) && isset($imageInfo[1])) {
                            $data['width'] = $imageInfo[0];
                            $data['height'] = $imageInfo[1];
                        }
                    } else {
                        $data['width'] = 0;
                        $data['height'] = 0;
                    }
                } else {
                    throw new BadRequestHttpException('Too big file, the max file size is ' . $file->getMaxFilesize());
                }
            } else {
                throw new BadRequestHttpException($file->getErrorMessage());
            }
        }

        return $data;
    }
1246962
public function process(File &$file, UploadedFile &$upload)
    {
        $mimeType = $upload->getClientMimeType();
        if ($mimeType == 'image/jpeg' || $mimeType == 'image/png') {
            $image = (new ImageManager())->make($upload->getRealPath());

            if ($this->settings->get('mustResize')) {
                $this->resize($image);
            }

            if ($this->settings->get('addsWatermarks')) {
                $this->watermark($image);
            }

            @file_put_contents(
                $upload->getRealPath(),
                $image->encode($upload->getClientMimeType())
            );
        }
    }
120663
public function sendResponseHttpHeaders(ResponseInterface $response):void
    {
        // checking
        if (headers_sent()) {
            throw new ResponseSenderException("A response has already been sent to the web browser",
                $this);
        }

        // removing PHP native HTTP headers (if enabled)
        if ($this->removePhpHttpHeaders) {
            foreach (headers_list() as $header) {
                header_remove(explode(":", $header)[0]);
            }
        }

        // sending response HTTP headers
        $this->sendHttpVersionHeader(
            $response->getProtocolVersion(),
            $response->getStatusCode(),
            $response->getReasonPhrase()
        );
        $this->sendHttpHeaders($this->listResponseHeaders($response));
    }
1111697
public function set(string $name, UploadedFileInterface $uploadedFile): void
    {
        $this->uploadedFiles[$name] = $uploadedFile;
    }
684736
public function uploadAction(ServerRequestInterface $request): ResponseInterface
    {
        $all_folders = $this->allMediaFolders();

        foreach ($request->getUploadedFiles() as $key => $uploaded_file) {
            if ($uploaded_file->getError() !== UPLOAD_ERR_OK) {
                FlashMessages::addMessage(Functions::fileUploadErrorText($uploaded_file->getError()), 'danger');
                continue;
            }
            $key = substr($key, 9);

            $folder   = $request->getParsedBody()['folder' . $key];
            $filename = $request->getParsedBody()['filename' . $key];

            // If no filename specified, use the original filename.
            if ($filename === '') {
                $filename = $uploaded_file->getClientFilename();
            }

            // Validate the folder
            if (!$all_folders->contains($folder)) {
                break;
            }

            // Validate the filename.
            $filename = str_replace('\\', '/', $filename);
            $filename = trim($filename, '/');

            if (strpos('/' . $filename, '/../') !== false) {
                FlashMessages::addMessage('Folder names are not allowed to include “../”');
                continue;
            }

            if (preg_match('/([:])/', $filename, $match)) {
                // Local media files cannot contain certain special characters, especially on MS Windows
                FlashMessages::addMessage(I18N::translate('Filenames are not allowed to contain the character “%s”.', $match[1]));
                continue;
            }

            if (preg_match('/(\.(php|pl|cgi|bash|sh|bat|exe|com|htm|html|shtml))$/i', $filename, $match)) {
                // Do not allow obvious script files.
                FlashMessages::addMessage(I18N::translate('Filenames are not allowed to have the extension “%s”.', $match[1]));
                continue;
            }

            // The new filename may have created a new sub-folder.
            $full_path = WT_DATA_DIR . $folder . $filename;
            $folder    = dirname($full_path);

            // Make sure the media folder exists
            if (!is_dir($folder)) {
                if (File::mkdir($folder)) {
                    FlashMessages::addMessage(I18N::translate('The folder %s has been created.', Html::filename($folder)), 'info');
                } else {
                    FlashMessages::addMessage(I18N::translate('The folder %s does not exist, and it could not be created.', Html::filename($folder)), 'danger');
                    continue;
                }
            }

            if (file_exists($full_path)) {
                FlashMessages::addMessage(I18N::translate('The file %s already exists. Use another filename.', $full_path, 'error'));
                continue;
            }

            // Now copy the file to the correct location.
            try {
                $uploaded_file->moveTo($full_path);
                FlashMessages::addMessage(I18N::translate('The file %s has been uploaded.', Html::filename($full_path)), 'success');
                Log::addMediaLog('Media file ' . $full_path . ' uploaded');
            } catch (Throwable $ex) {
                FlashMessages::addMessage(I18N::translate('There was an error uploading your file.') . '<br>' . $ex->getMessage(), 'danger');
            }
        }

        $url = route('admin-media-upload');

        return redirect($url);
    }
301654
static function dropzoneUpload ($request, $response)
  {
    $ds = DIRECTORY_SEPARATOR;
    $storeFolder = self::TEMP_STORE_FOLDER_NAME;
    $storePath = sys_get_temp_dir().$ds.$storeFolder;

    if (!is_dir($storePath))
      mkdir($storePath);

    $file = "";
    foreach ($request->getUploadedFiles() as $oFile)
    {
      $filename = $oFile->getClientFilename ();
      $filePath = $storePath.$ds.$filename;
      $oFile->moveTo($filePath);
      $file = $filePath;
    }
    return Http::jsonResponse ($response,$file);
  }
965078
public function loadIgnoreResponse(string $file, ResponseInterface $response) : ResponseInterface
    {
        return $this->includeResponse('loadIgnore', $file, $response);
    }
1265350
public function beforeMethod(RequestInterface $request, ResponseInterface $response)
    {
        if ($this->currentPrincipal) {
            // We already have authentication information. This means that the
            // event has already fired earlier, and is now likely fired for a
            // sub-request.
            //
            // We don't want to authenticate users twice, so we simply don't do
            // anything here. See Issue #700 for additional reasoning.
            //
            // This is not a perfect solution, but will be fixed once the
            // "currently authenticated principal" is information that's not
            // not associated with the plugin, but rather per-request.
            //
            // See issue #580 for more information about that.
            return;
        }

        $authResult = $this->check($request, $response);

        if ($authResult[0]) {
            // Auth was successful
            $this->currentPrincipal = $authResult[1];
            $this->loginFailedReasons = null;

            return;
        }

        // If we got here, it means that no authentication backend was
        // successful in authenticating the user.
        $this->currentPrincipal = null;
        $this->loginFailedReasons = $authResult[1];

        if ($this->autoRequireLogin) {
            $this->challenge($request, $response);
            throw new NotAuthenticated(implode(', ', $authResult[1]));
        }
    }
478788
public function sendResponse(ResponseInterface $response)
    {
        $e = $this->getEvent();
        $e->setResponse($response);

        $e->getApplication()->getEventManager()->trigger(MvcEvent::EVENT_FINISH, $e);
        exit();
    }
94806
protected function prepareForeach(UploadedFile $image = null)
    {
        $this->name = $this->getStoreName($image);

        $this->callInterventionMethods($image->getRealPath());

        return tap($this->upload($image), function () {
            $this->name = null;
        });
    }