Display A File's Content On A Content Page.

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
Zippo
Forum Members
Forum Members
Posts: 15
Joined: Mon Jan 31, 2022 12:19 am

Display A File's Content On A Content Page.

Post by Zippo »

I thought that maybe I could use a simple UDT for this with the following PHP code:

$myfile = fopen("uploads/docs/test.txt", "r") or die("Unable to open file!");
echo fread($myfile,filesize("test.txt"));
fclose($myfile);

Unfortunately, it appears that the path isn't correct as the file won't open. How can I figure out what the path should be to make this work?
Zippo
Forum Members
Forum Members
Posts: 15
Joined: Mon Jan 31, 2022 12:19 am

Re: Display A File's Content On A Content Page. Solved

Post by Zippo »

Shoot! Sorry. Very easy:

echo getcwd();
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: Display A File's Content On A Content Page.

Post by DIGI3 »

If you want to do it without a UDT, Smarty has a {fetch} tag:
https://www.smarty.net/docs/en/language ... .fetch.tpl

It currently does require permissive_smarty to be enabled in your config file though.
Not getting the answer you need? CMSMS support options
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Display A File's Content On A Content Page.

Post by Rolf »

- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Zippo
Forum Members
Forum Members
Posts: 15
Joined: Mon Jan 31, 2022 12:19 am

Re: Display A File's Content On A Content Page.

Post by Zippo »

DIGI3 wrote: Wed Feb 23, 2022 8:57 pm If you want to do it without a UDT, Smarty has a {fetch} tag:
https://www.smarty.net/docs/en/language ... .fetch.tpl

It currently does require permissive_smarty to be enabled in your config file though.
Thank you, DIGI3! This does try to work but you're correct. I get a permission denied by SMARTY error. Unfortunately, I do not know enough about CMS or SMARTY to know what the repercussions for the website would be if I made SMARTY permissive.
Zippo
Forum Members
Forum Members
Posts: 15
Joined: Mon Jan 31, 2022 12:19 am

Re: Display A File's Content On A Content Page.

Post by Zippo »

Rolf wrote: Thu Feb 24, 2022 6:04 pm You could also use:
http://dev.cmsmadesimple.org/projects/cacheremotefile

Demo and tutorial at:
https://cmscanbesimple.org/blog/share-d ... e-file-tag
Thank you, Rolf! This looks a bit cumbersome for just showing the contents of a local text file on a local Content page, but I'll check it out in more detail
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: Display A File's Content On A Content Page.

Post by DIGI3 »

It's only a concern if you're allowing front-end editing that also allows Smarty tags (like allowing Front End Users to post news articles, and your News template evals that Smarty). If only trusted people have access to edit things, it doesn't really change the risk level to enable permissive_smarty. The goal is to limit the damage a not-fully-trusted editor can do.
Not getting the answer you need? CMSMS support options
Zippo
Forum Members
Forum Members
Posts: 15
Joined: Mon Jan 31, 2022 12:19 am

Re: Display A File's Content On A Content Page.

Post by Zippo »

DIGI3 wrote: Wed Mar 02, 2022 11:19 pm It's only a concern if you're allowing front-end editing that also allows Smarty tags (like allowing Front End Users to post news articles, and your News template evals that Smarty). If only trusted people have access to edit things, it doesn't really change the risk level to enable permissive_smarty. The goal is to limit the damage a not-fully-trusted editor can do.
Thank you. How do I enable permissive mode? Does permissive mode apply to the whole site or can it be limited to a page or pages? Do you think that's also what's keeping the fopen() from working? Thanks again. I really do appreciate the help.
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: Display A File's Content On A Content Page.

Post by DIGI3 »

Not getting the answer you need? CMSMS support options
Zippo
Forum Members
Forum Members
Posts: 15
Joined: Mon Jan 31, 2022 12:19 am

Re: Display A File's Content On A Content Page.

Post by Zippo »

DIGI3 wrote: Thu Mar 03, 2022 2:15 am https://docs.cmsmadesimple.org/configur ... ive_smarty

and no, nothing to do with fopen.
Thanks, but still not working. I added the tag $config['permissive_smarty'] = 1; to my config.php file but still getting an error when attempting to fetch the file. I've tried with a text file and a PDF.

My call from the Content Page, is {fetch file="/uploads/docs/text.txt"}

The error is:
ERROR at line 212 of file /../public_html/lib/smarty/plugins/function.fetch.php:

{fetch} cannot read resource '/uploads/docs/text.txt'

I'm a bit stuck on what to try next. Thanks!
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: Display A File's Content On A Content Page.

Post by DIGI3 »

I think you need to use the full path to the file, not just from the site route. I haven't checked in a while though. Depending on your server environment it would be something like /yourhostingaccount/public_html/uploads/...
Not getting the answer you need? CMSMS support options
Zippo
Forum Members
Forum Members
Posts: 15
Joined: Mon Jan 31, 2022 12:19 am

Re: Display A File's Content On A Content Page. Solved

Post by Zippo »

DIGI3 wrote: Thu Mar 03, 2022 4:09 pm I think you need to use the full path to the file, not just from the site route. I haven't checked in a while though. Depending on your server environment it would be something like /yourhostingaccount/public_html/uploads/...
Oh, man! That did it! Thank you so much for the help. I'm gonna make sure there's something a little extra in your check next week! ;D

Thanks again for your patient assistance DIGI3. Very much appreciated.
Post Reply

Return to “Modules/Add-Ons”