Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Including a .txt file in an article
<p>Hi,</p>
<p>I’ve created a custom field called NewLinks and want to use it to specify the name of the file that should be included.</p>
<p>I tried the following in a form but it didn’t work:</p>
<code>
<txp:php>
<? include (“<txp:custom_field name=“NewLinks” />”); ?>
</txp:php>
</code>
<p>The error I get is…</p>
<p>Parse error: parse error in c:\program files\easyphp1-8\www\fpp\textpattern\publish\taghandlers.php(1726) : eval()’d code on line 2</p>
<p>I’m getting the same result with the filename directly in the form:</p>
<code>
<txp:php>
<? include (“news.txt”); ?>
</txp:php>
</code>
<p>Any ideas?</p>
<p>Thanks,</p>
<p>Loz</p>
Last edited by lozmatic (2006-08-27 22:02:08)
Offline
Re: Including a .txt file in an article
Try: <del><code> <txp:php> include (“<txp:custom_field name=“NewLinks” />”); </txp:php></code></del>
or: <code><txp:php> include (“news.txt”); </txp:php></code>
Last edited by ruud (2006-08-28 09:17:49)
Offline
#3 2006-08-28 04:18:23
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Including a .txt file in an article
<txp:php>include(custom_field(array('name' => 'NewLinks')));</txp:php>
<txp:php>include('news.txt");</txp:php>
Offline
Re: Including a .txt file in an article
Hi ,
I’m getting the following error which indicates to me that there is something wrong with how my PC is set up…
tag_error <txp:php> -> Warning: (null)(): Failed opening ‘’ for inclusion (include_path=’.;C:/Program Files/EasyPHP1-8\php\pear\’) on line 1
Thanks for your help :)
Offline
#5 2006-08-28 23:49:39
- NyteOwl
- Member
- From: Nova Scotia, Canada
- Registered: 2005-09-24
- Posts: 539
Re: Including a .txt file in an article
lozmatic wrote:
tag_error <txp:php> -> Warning: (null)(): Failed opening ‘’ for inclusion (include_path=’.;C:/Program Files/EasyPHP1-8\php\pear\’) on line 1
Check your path mixture of ‘/’ and ‘\’
Obsolescence is just a lack of imagination. / 36-bits Forever! / #include <disclaimer.h>;
Offline
Re: Including a .txt file in an article
Hi,
This worked in the end :)
But I’m hoping to save a custom field by having the php open a file that is named [url_title].txt and saved in the files directory (where uploaded files are saved).
So if i publish ‘13’ in the field the URL-only title filed the php would have to look for a file published here: files/13.txt
<code>
<txp:php>include(custom_field(array(‘name’ => ‘url_title’)));</txp:php>
</code>
This will only return ‘13’ and not ‘files/13.txt’ so I get a ‘No such file or directory’ error.
I hope this makes sense!
Last edited by lozmatic (2006-10-01 23:48:43)
Offline
#7 2006-10-02 03:17:51
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Including a .txt file in an article
Try:
<txp:php>global $file_base_path; include($file_base_path.DS.custom_field(array('name' => 'url_title'))).'.txt';</txp:php>
:)
Last edited by Mary (2006-10-03 03:22:06)
Offline
Re: Including a .txt file in an article
Thanks Mary,
does that print the .txt bit too?
I guess I could always have a file without an extension.
Offline
#9 2006-10-03 01:15:40
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Including a .txt file in an article
I updated the code. :)
Offline
Re: Including a .txt file in an article
Mary,
I hate haveing to ask you again… and I did try to figure it out, honestly!
The output is…
www\textpattern\files13.txt
I just need one extra \ after files and it will work!
I tried this but it didn’t work:
<code>
<txp:php>global $file_base_path; include($file_base_path.’\’.custom_field(array(‘name’ => ‘url_title’))).’.txt’;</txp:php>
</code>
Not sure why, and for some reason I have this feeling that some + symbols are missing.
Loz
(I should leanrn PHP, really)
Offline
#11 2006-10-03 03:11:54
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Including a .txt file in an article
Ah yes, forgot the slash too.
It looks like your files path (advanced admin prefs) is incorrect (something’s missing from in front of “www”). If you go to your diagnostics tab, you will see “$path_to_site:”. How does it compare to your files path?
Offline
Re: Including a .txt file in an article
I added a / at the end and noe wit works wonderfully :)
Thank you very much.
Offline
Pages: 1