app/Http/Controllers/MediaFileController.php
public function mediaDownload(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $xref    = $request->get('xref', '');
        $fact_id = $request->get('fact_id');
        $media   = Media::getInstance($xref, $tree);

        if ($media === null) {
            throw new MediaNotFoundException();
        }

        if (!$media->canShow()) {
            throw new AccessDeniedHttpException();
        }

        foreach ($media->mediaFiles() as $media_file) {
            if ($media_file->factId() === $fact_id) {
                if ($media_file->isExternal()) {
                    return redirect($media_file->filename());
                }

                if (!$media_file->isImage() && $media_file->fileExists()) {
                    $data = file_get_contents($media_file->getServerFilename());

                    return response($data, StatusCodeInterface::STATUS_OK, [
                        'Content-Type' => $media_file->mimeType(),
                        'Content-Disposition' => 'attachment; filename="' . addcslashes($media_file->filename(), '"') . '"',
                    ]);
                }
            }
        }

        throw new NotFoundHttpException();
    }
public function mediaDownload(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $xref    = $request->get('xref', '');
        $fact_id = $request->get('fact_id');
        $media   = Media::getInstance($xref, $tree);

        if ($media === null) {
            throw new MediaNotFoundException();
        }

        if (!$media->canShow()) {
            throw new AccessDeniedHttpException();
        }

        foreach ($media->mediaFiles() as $media_file) {
            if ($media_file->factId() === $fact_id) {
                if ($media_file->isExternal()) {
                    return redirect($media_file->filename());
                }

                if (!$media_file->isImage() && $media_file->fileExists()) {
                    $data = file_get_contents($media_file->getServerFilename());

                    return response($data, StatusCodeInterface::STATUS_OK, [
                        'Content-Type' => $media_file->mimeType(),
                        'Content-Disposition' => 'attachment; filename="' . addcslashes($media_file->filename(), '"') . '"',
                    ]);
                }
            }
        }

        throw new NotFoundHttpException();
    }
public function mediaDownload ( ServerRequestInterface $ request , Tree $ tree ) : ResponseInterface { $ xref = $ request -> get ( 'xref' , '' ) ; $ fact_id = $ request -> get ( 'fact_id' ) ; $ media = Media :: getInstance ( $ xref , $ tree ) ; if ( $ media === null ) { throw new MediaNotFoundException ( ) ; } if ( ! $ media -> canShow ( ) ) { throw new AccessDeniedHttpException ( ) ; } foreach ( $ media -> mediaFiles ( ) as $ media_file ) { if ( $ media_file -> factId ( ) === $ fact_id ) { if ( $ media_file -> isExternal ( ) ) { return redirect ( $ media_file -> filename ( ) ) ; } if ( ! $ media_file -> isImage ( ) && $ media_file -> fileExists ( ) ) { $ data = file_get_contents ( $ media_file -> getServerFilename ( ) ) ; return response ( $ data , StatusCodeInterface :: STATUS_OK , [ 'Content-Type' => $ media_file -> mimeType ( ) , 'Content-Disposition' => 'attachment; filename="' . addcslashes ( $ media_file -> filename ( ) , '"' ) . '"' , ] ) ; } } } throw new NotFoundHttpException ( ) ; }
Download a non-image media file.

@param ServerRequestInterface $request
@param Tree                   $tree

@return ResponseInterface
Download a non - image media file .