Page 1 of 1

Direct HTTP response from a module

Posted: Tue Nov 15, 2005 10:43 am
by matt
All,

I wan't to implement a module, that can store images in the database and display them in tags. The only way I know to do that is to store base64 encoded images, load them, decode and send as an HTTP response when browser requests URL from the tag.

Like this:

Code: Select all

header("Content-type: ".$record['type']);
header("Content-length: ".$record['size']);
header("Content-Disposition: attachment; filename=".$record['name']);
header("Content-Description: Attachment");
echo base64_decode($record['content']);
Where $record is a db row.

Is there a way to do it from a module? Because as far as I know modules only insert their content into a template. How to send just this HTTP response?

Alternatively - what would be the best place in CMSMS to implement such a response while at the same time using the db connection or any other required stuff already in CMSMS?

Thanks,
Matt.

Re: Direct HTTP response from a module

Posted: Tue Nov 15, 2005 2:42 pm
by calguy1000
The Uploads module does similar things to send files to people, you can do a search through this for "header" tags for a reference.

Re: Direct HTTP response from a module

Posted: Wed Nov 16, 2005 8:27 am
by jah
Hi Matt,

I once started developing a module to list employees. One of the fields was a picture of the person.
The picture was stored in the DB as a blob and then a PHP file generated the image in an IMG tag.

Install the attached module and see if you can use something here (In the Admin it shows up under content, I think).

The module is FAAAR from finished, so I aplogise for the mess.

The attachement must be renamed to .zip

Jon

[attachment deleted by admin]

Re: Direct HTTP response from a module

Posted: Wed Nov 16, 2005 9:18 am
by matt
Guys,

Thanks for your help. It seems adding a call to exit(), after sending out the header and the content, is enough.

Matt.