CRUDlex\ControllerProvider::staticFile PHP Method

staticFile() public method

The controller for serving static files.
public staticFile ( Request $request, Silex\Application $app ) : Response
$request Symfony\Component\HttpFoundation\Request the current request
$app Silex\Application the Silex application
return Symfony\Component\HttpFoundation\Response redirects to the instance details page or 404 on invalid input
    public function staticFile(Request $request, Application $app)
    {
        $fileParam = str_replace('..', '', $request->get('file'));
        $file = __DIR__ . '/../static/' . $fileParam;
        if (!$fileParam || !file_exists($file)) {
            return $this->getNotFoundPage($app, $app['translator']->trans('crudlex.resourceNotFound'));
        }
        $mimeTypes = new MimeTypes();
        $mimeType = $mimeTypes->getMimeType($file);
        $size = filesize($file);
        $streamedFileResponse = new StreamedFileResponse();
        $response = new StreamedResponse($streamedFileResponse->getStreamedFileFunction($file), 200, ['Content-Type' => $mimeType, 'Content-Disposition' => 'attachment; filename="' . basename($file) . '"', 'Content-length' => $size]);
        $response->setETag(filemtime($file))->setPublic()->isNotModified($request);
        $response->send();
        return $response;
    }