Yes - you'll need to turn on output buffering. In my applications I usually create a function similar to die() which clears all output buffers and then outputs the error:

Something like this:
PHP Code:
<?php
    
function error ($msg)
    {
        
$level ob_get_level();

        while (
$level 0) {
            
ob_end_clean();
            --
$level;
        }
?>
    <html>
    <head>
        <title>Photo Albums - Error</title>
    </head>
    <body>
        <span class="error"><?php echo($msg?></span>
    </body>
<?php
        
exit;
    }
?>