Auto-loading a text file into a textarea?

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
skylark2
Forum Commoner
Posts: 32
Joined: Wed Jun 16, 2010 6:00 am

Auto-loading a text file into a textarea?

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

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

Post 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>
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
skylark2
Forum Commoner
Posts: 32
Joined: Wed Jun 16, 2010 6:00 am

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

Post 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.
Post Reply