Direct HTTP response from a module

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
matt

Direct HTTP response from a module

Post 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.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Direct HTTP response from a module

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
jah
Forum Members
Forum Members
Posts: 147
Joined: Thu Dec 30, 2004 9:09 am

Re: Direct HTTP response from a module

Post 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]
matt

Re: Direct HTTP response from a module

Post 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.
Locked

Return to “CMSMS Core”