[SOLVED] Linking to a file in the modules/<modulename>/ folder

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
RustyXXL
New Member
New Member
Posts: 6
Joined: Tue Jun 15, 2010 8:26 am

[SOLVED] Linking to a file in the modules/<modulename>/ folder

Post by RustyXXL »

Hi,

I'm developing a Made Simple Module at work and would like to offer a kind of "log" to be downloaded from the admin panel. I already have the Code for the file, and it's working, but i'm linking to the file with

Code: Select all

<form action="../modules/<modulename>/filename.php" method="post">
Well, i think this is pretty dirty, and would like to ask if there is a better Solution using a function like CreateFormStart().
The Problems I'm running into are:

1. CreateFormStart() doesn't allow me to use an own action-target, only the cms ms action, which isn't quite the same.

2. I'd prefer if I wouldn't need to hardcode the path to the file, as it may change at some point.

Unfortunatly I can't find a solution to this problems atm, I've searched in the Apidoc, but wasn't able to find anything which would solve my Problems.

Greetings, Rusty
Last edited by RustyXXL on Tue Jul 06, 2010 9:34 am, edited 1 time in total.
NaN

Re: Linking to a file in the modules/<modulename>/ folder

Post by NaN »

Sorry but i don't understand the whole problem.
CreateFormStart does allow own action targets. (as long if it s an action of a CMSms module)
All you need to do ist to create a proper action.

Example:

If your action is named "myAction" you need a file named action.myAction.php.
Create your form targetting this action like this:

$this->CreateFormStart($id, 'myAction', $returnid, 'post', 'multipart/form-data', false, '', array('param'=>$value, ... ));

So where is the problem?
If you don't want to target a "CMSms action" the usage of the CMSms API doesn't make sense to me.
If you want to target a file directly outside of the CMSms context you need to do this hardcoded.
Salketer

Re: Linking to a file in the modules/<modulename>/ folder

Post by Salketer »

I assume you know how to create a module action.

You can call the action from a form or a link using the built-in functions like RustyXXL pointed out. You can create a parameter in your module to hold your log file path and retrieve it in your log-grabbing action or pass the path in the form or link.

Now you will want to send the file to the browser for download so call your module action with the parameter disable_theme = 1 added to the other parameters to make sure CMSMS does not output any templates. In your action you can then open the file and echo/print out its data (or simply include the file) once you set the proper headers.

Your action would look something like this:

Code: Select all

//D'ONT FORGET YOUR PERMISSION CODE!
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=logfile.xls ");
header("Content-Transfer-Encoding: binary ");
include("report.txt");
This might not be the most secure way to do it but since you are the one adding content to the file there should be no problem at all. Just make sure no one has access to the file.
RustyXXL
New Member
New Member
Posts: 6
Joined: Tue Jun 15, 2010 8:26 am

Re: Linking to a file in the modules/<modulename>/ folder

Post by RustyXXL »

Thanks for the answers, and I'm sorry I couldn't answer earlier.

I think the parameter disable_theme will help me a lot with my problem, as I always had html-stuff in my log when i used API-Functions.
I'll try to include this in my code and come back to you with my results as soon as I can.

Thx & Greets
Rusty
RustyXXL
New Member
New Member
Posts: 6
Joined: Tue Jun 15, 2010 8:26 am

Re: Linking to a file in the modules/<modulename>/ folder

Post by RustyXXL »

Well i finally could work on it again and it works pretty well now with the disable_theme param, except that now cmsms adds

Code: Select all

</div><!-- admin theme disabled -->
<__body>
</__html>

<!-- 0.027977 /  / 489760 / 7715880 -->
at the end of the file.
I can't find a solution on how to remove this too, as it's a little bit annoying.
Another little bit of help would be really nice on where this come from and how to remove it. :)

Greets, Rusty

Edit:
Well i solved it with adding a die(); after the output of the file.
Last edited by RustyXXL on Tue Jul 06, 2010 9:35 am, edited 1 time in total.
Salketer

Re: [SOLVED] Linking to a file in the modules/<modulename>/ folder

Post by Salketer »

There is a better way of adding it than the die() solution. I saw this on the forum a couple of times, just make a search.
Post Reply

Return to “Developers Discussion”