if $attachEnabled is false, then $file must be NULL
there remains an issue with viewfile