Page 1 of 1

Display A File's Content On A Content Page.

Posted: Wed Feb 23, 2022 6:50 pm
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?

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

Posted: Wed Feb 23, 2022 6:54 pm
by Zippo
Shoot! Sorry. Very easy:

echo getcwd();

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

Posted: Wed Feb 23, 2022 8:57 pm
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.

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

Posted: Thu Feb 24, 2022 6:04 pm
by Rolf

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

Posted: Wed Mar 02, 2022 11:16 pm
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.

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

Posted: Wed Mar 02, 2022 11:18 pm
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

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

Posted: Wed Mar 02, 2022 11:19 pm
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.

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

Posted: Thu Mar 03, 2022 2:00 am
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.

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

Posted: Thu Mar 03, 2022 2:15 am
by DIGI3

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

Posted: Thu Mar 03, 2022 4:07 pm
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!

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

Posted: Thu Mar 03, 2022 4:09 pm
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/...

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

Posted: Fri Mar 04, 2022 3:10 am
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.