Delivering an image from C5

Permalink
What I need to do is to have an image dynamically provided by a page in C5 which has an image library block in it I've written. Should be the easiest thing in the world but it's not working for some reason. Code as follows:

ob_end_clean();
      switch($ext) {
         case 'jpeg' :
         case 'jpg' :
            header('Content-type: image/jpeg');
            break;
         case 'bmp' :
            header('Content-type: image/bmp');
            break;
         case 'gif' :
            header('Content-type: image/gif');
            break;
         case 'png' :
            header('Content-type: image/png');
            break;


I don't think I've ever known a buffer flush followed by a header change a readfile and a die not to work from anywhere!

Is being done this way (from within the block, triggered by a URL param of a file download ID) so that the C5 user groups are automatically enforced. Seemed the least-fuss approach though it's just not working.

If the content-type header is suppressed the readfile delivers the binary data. If the content-type is allowed to be output then the readfile appears to deliver nothing!

I'm sure it's something stupid that's causing it but just not seeing it.

surefyre