Page 1 of 1

Auto-loading a text file into a textarea?

Posted: Thu Sep 09, 2010 5:36 am
by skylark2
Newbie here, porting an old Windows program.

What I want to do is simply display a plain text file on the screen with a couple of buttons underneath it. From what I've read, the way to do this is to turn it into a very basic xml file and reference that. So I have in my header:

Code: Select all

<?php
$file = $_GET['file'];
$output = '<xml id="Txt" src="'.$file.'"></xml>';
echo $output;
?>
and in the main body

Code: Select all

  <textarea name="displayfile" datasrc="#Txt" cols="80" rows="20">

  </textarea>
No text comes up, just a blank text area. However, if I go to view the page source it looks right with the correct filename, and if I click on the xml file in the page source the file comes up.

xml file is very simple:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<TextOnly>
<Content>
                          (here is my content)
</Content>
</TextOnly>
Can anyone tell me what I missed please?

Re: Auto-loading a text file into a textarea?

Posted: Fri Sep 10, 2010 12:28 pm
by pickle
There's no need for XML here - at least from what I can gather by your post.

I guess how you do it is dependent on what you want those buttons to do. If you just want to display the file as plain text on the screen, just call readfile() on the file path.

Re: Auto-loading a text file into a textarea?

Posted: Fri Sep 10, 2010 12:38 pm
by AbraCadaver
Yeah, I have no idea what you're doing with the first bit of code. There is nothing inside the text area. Thsi will do it:

Code: Select all

<textarea name="displayfile" cols="80" rows="20">
<?php readfile("/path/to/$file"); ?>
</textarea>

Re: Auto-loading a text file into a textarea?

Posted: Wed Sep 15, 2010 3:20 am
by skylark2
Brilliant!

Many thanks guys - obviously my Google-fu failed me. All I could find was comments that you had to use XML. I'm still at that stage of newbieness that I don't know where to start looking for things :(

The buttons are Print and "go to other page", so I can't see that being an issue.