-
- 22 Posts
I want write a snippet/plugin which I can place in a resource with no template that will take a file path passed to it in a GET parameter and force the browser to download that file rather than render it - will be used for PDF’s, JPEG’s and other files that the browser would normally try to display.
The issue I am having is that because my snippet is running inside a resource it generates ’headers already sent’ errors becaue of the headers already sent by ModX. Because the snippet needs to handle various file types both the content-disposition and content-type headers need to be set dynamically as well as some others for file size etc.
So my question is, can I dymanically change the headers output by ModX and if so, can anyone point me at some docs that would be useful in doing so?
Why not use Static Resources for this? There is no need to write this kind of Snippet since MODX handles this natively using Content Type and Content Disposition data. You also can’t cache the data, protect it, or generate URLs easily for the files this way. Why not just have a script outside of MODX do this?
-
- 22 Posts
I could do that of course but it would have been handy to do in ModX for reuse as I wouldn’t have to reset paths on every deployment - could use $modx->getOption(’base_path’) plus tweak the code through the manager. Seems a common enough task people would have to address and figured there might be a way to access the headers via the API.
I suppose to get the base_path I can instantiate $modx in my script which will make it more portable.
Wouldn’t even need to instantiate $modx, just include the config.inc.php file and use the MODX_BASE_PATH comstant.
Just wondering; wouldnt the filelister addon help you out?
-
- 22 Posts
Didn’t know about filelister but will check it out - thanks Mark.