Q:

Private images in Symfony2

I have a little problem with my Symfony installation. In my app the user can upload images to the server and the images are stored in /web/uploads/images. I would like that the image be only visible for logged users into the app.
I have tried to modify the security configuration but I don't find the proper configuration to solve the problem. Any idea??
Thanks :)

A:

Firstly thank you very much for take your time to answer :) I think that both solutions are valid. In my particular case I have implemented the solution proposed by @Patrick. 
Coming soon I will need the private images accessible from a mobile app through and url, so for that reason I have implemented a controller instead a twig extension, the controller's code is following:
<?php

namespace Company\Bundle\nameBundle\Controller;

use Symfony\Component\HttpFoundation\Response,
Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DashPrivateImageController extends Controller
{
    public function getImageAction($imagetype, $imagename) {

        $securityContext = $this->container->get('security.context');

        if ($securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {

            if ($imagetype == 1) 
                $path = $this->get('kernel')->getRootDir() . "/../private/documentFolder1/" . $imagename;
            else 
                $path = $this->get('kernel')->getRootDir() . "/../private/documentFolder2/" . $imagename;

            $file = file_get_contents($path);
            $headers = array('Content-Type' => 'image/jpeg', 
                       'Content-Disposition' => 'inline; filename="'.$imagename.'"');
            return new Response($file, 200, $headers);
        } else 
            return new Response("not found", 404);
    }
}
?>

Thanks!!

