[solved] Correct way to set MIME type

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Locked
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

[solved] Correct way to set MIME type

Post 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?
Last edited by Cerulean on Sat Oct 11, 2014 9:22 pm, edited 1 time in total.
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: Correct way to set MIME type

Post 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....
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

Re: Correct way to set MIME type

Post 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.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: [solved] Correct way to set MIME type

Post by Rolf »

For CMSMS 2.0 something like:

Code: Select all

$type = "application/pdf";
cmsms()->set_content_type($type);
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Locked

Return to “The Lounge”