Display A File's Content On A Content Page.
Display A File's Content On A Content Page.
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?
$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
Shoot! Sorry. Very easy:
echo getcwd();
echo getcwd();
Re: Display A File's Content On A Content Page.
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.
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
Re: Display A File's Content On A Content Page.
You could also use:
http://dev.cmsmadesimple.org/projects/cacheremotefile
Demo and tutorial at:
https://cmscanbesimple.org/blog/share-d ... e-file-tag
http://dev.cmsmadesimple.org/projects/cacheremotefile
Demo and tutorial at:
https://cmscanbesimple.org/blog/share-d ... e-file-tag
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Re: Display A File's Content On A Content Page.
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.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.
Re: Display A File's Content On A Content Page.
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 detailRolf 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
Re: Display A File's Content On A Content Page.
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
Re: Display A File's Content On A Content Page.
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.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.
Re: Display A File's Content On A Content Page.
Not getting the answer you need? CMSMS support options
Re: Display A File's Content On A Content Page.
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.DIGI3 wrote: ↑Thu Mar 03, 2022 2:15 am https://docs.cmsmadesimple.org/configur ... ive_smarty
and no, nothing to do with fopen.
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.
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
Re: Display A File's Content On A Content Page. Solved
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!
Thanks again for your patient assistance DIGI3. Very much appreciated.