[Solved] include a text file in a page

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
User avatar
trainer
Forum Members
Forum Members
Posts: 43
Joined: Sat Jun 19, 2010 9:58 am

[Solved] include a text file in a page

Post by trainer »

Hello,
I would like to include a text file in some of my pages.

What is the correct way to do this?

I have tried UDTs but I'm not getting anywhere.

Code: Select all

include ("test.txt");
I've also tried it with a URL and variations of the path and also an absolute path - but still no luck.

Is there another method? (not UDT maybe...?)

I'd appreciate any advice. :)
Last edited by trainer on Fri Oct 28, 2011 7:59 pm, edited 1 time in total.
CMSMS 1.11.1
PHP Version 5.3.3-1ubuntu9.7
MySQL 4.1.22
Apache 2.2.16 (Ubuntu)
Linux 2.6.35-22
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: include a text file in a page

Post by Wishbone »

The UDT:

Code: Select all

echo("<pre>");
readfile($params['file']);
echo("</pre>");
The call:

Code: Select all

{read_text_file file=stylesheet.css}
http://teamwishbone.com/1941/index.php?page=text-file
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: include a text file in a page

Post by calguy1000 »

Code: Select all

{'path/to/filename.txt'|readfile} 
would probably work too.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: include a text file in a page

Post by Wishbone »

That works, but ignores new lines... I tried

{'stylesheet.css'|readfile|nl2br}

but for some reason, it's not converting the new lines to line breaks
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: include a text file in a page

Post by calguy1000 »

This works fine:

Code: Select all

<pre>{'stylesheet.css'|readfile}</pre>
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: include a text file in a page

Post by calguy1000 »

Though, hypothetically speaking, a geshi wrapper module would be sexy.
Does somebody wanna write one?
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: include a text file in a page

Post by Wishbone »

calguy1000 wrote:Though, hypothetically speaking, a geshi wrapper module would be sexy.
Does somebody wanna write one?
I had to look that up... Sounds like it would be a fun module to make... No code formatting modules in the Forge?
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: include a text file in a page

Post by Wishbone »

It looks like there is the UpHyperlight module, but I have no idea how it compares to GeSHi.

http://dev.cmsmadesimple.org/projects/uphyperlight
User avatar
trainer
Forum Members
Forum Members
Posts: 43
Joined: Sat Jun 19, 2010 9:58 am

Re: include a text file in a page

Post by trainer »

It works!

Thanks a lot guys - I really appreciate your responses :)


BTW, would I use this method for including other cmsms pages?
Or is there a different (proper) way of doing that?
CMSMS 1.11.1
PHP Version 5.3.3-1ubuntu9.7
MySQL 4.1.22
Apache 2.2.16 (Ubuntu)
Linux 2.6.35-22
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: include a text file in a page

Post by Wishbone »

No.. CMSMS pages aren't files. Take a look at the CGSimpleSmarty module for easy ways to include other pages content.
User avatar
trainer
Forum Members
Forum Members
Posts: 43
Joined: Sat Jun 19, 2010 9:58 am

Re: include a text file in a page

Post by trainer »

Will do - thanks again. :)
CMSMS 1.11.1
PHP Version 5.3.3-1ubuntu9.7
MySQL 4.1.22
Apache 2.2.16 (Ubuntu)
Linux 2.6.35-22
Post Reply

Return to “CMSMS Core”