Show image through controller

Hi,

I have some images saved in an secure folder (Order deny,allow Deny from all).

I want to display them by an simple request if the user has the permission to see it. My problem is, I don’t get it working in Yii. It’s no problem with an simple php script but in Yii the browser tells me everytime it’s a broke imagefile.




if(file_exists($filePath)) {

            header('Pragma: public');

            header('Expires: 0');

            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

            header("Cache-Control: private");

            header("Content-Type: image/jpg");

            header('Content-Transfer-Encoding: binary');

            header("Content-Length: ".filesize($filePath));

            header('Connection: close');


            readfile($filePath);

        }



How should I send the header informations through yii controller?

I found a workaround. Using ob_end_clean() to clear output from everthing else from yii. But thats not a nice solution. It would be nice to know a good solution for this problem.