Page 1 of 1

[solved] Correct way to set MIME type

Posted: Sat Oct 11, 2014 4:58 am
by Cerulean
I'm using a UDT to generate PDF files dynamically via mPDF. I'm calling my UDT with "showtemplate=false" in the query string but was finding that the generated file was receiving the wrong MIME type in the header so that it was displaying as HTML rather than a PDF.

My question is: what is the right way to set the MIME type in my UDT? A Google search revealed a blog post referring to

Code: Select all

cmsms()->variables['content-type']
but I can't find any documentation on this.

I used

Code: Select all

cmsms()->variables['content-type'] = "application/pdf";
and it seems to work fine, but is this the correct method?

Re: Correct way to set MIME type

Posted: Sat Oct 11, 2014 6:05 pm
by JohnnyB
inmho, if it works, it is probably ok.
But, you should be able to set the mime type using php directly in the udt. I don't know if the CMSMS variable does the same thing or not, but, you can try setting like:

header('Content-Type: application/pdf');

It has to be set first, before any output....

Re: Correct way to set MIME type

Posted: Sat Oct 11, 2014 9:21 pm
by Cerulean
Thanks for the reply.

I tried

Code: Select all

header('Content-Type: application/pdf');
but the PDF was served as an HTM file.
I suspect CMSMS is setting the content type to text/html and this isn't successfully overridden by the php header function.

So the

Code: Select all

cmsms()->variables['content-type'] = "application/pdf";
method seems like the way to go. Like you say - it works so it's okay. I was just concerned it might be a deprecated method and there might be a more current one.

Re: [solved] Correct way to set MIME type

Posted: Sun Oct 12, 2014 8:41 am
by Rolf
For CMSMS 2.0 something like:

Code: Select all

$type = "application/pdf";
cmsms()->set_content_type($type);