PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Deemo
Forum Contributor
Posts: 418 Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC
Post
by Deemo » Sun Jun 20, 2004 6:06 pm
Hello guys
Here is my problem. I am making an application that is esentially like a remote file manager. This program works fine accessing html files, but i get many errors while reading php files. here is my code:
Code: Select all
<?php
$handle = fopen($Page, "r");
$lines = fread($handle, filesize($Page));
echo '<form action="admin.php?page=$Page&act=up" method="post">
<textarea rows="25" cols="100" name="html">$lines</textarea><input type="submit" value="Edit HTML">
</form>';
?>
The Problem is that when a php file is loaded up, i get a garbled up mess. What i think is being done is the php code is actually being evaluated. How do i make it so that none of the php code is read, it is just outputted to the textarea element?
Thanks
Deemo
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sun Jun 20, 2004 6:20 pm
PHP variables don't get interpolated (evaluated) inside single quotes, so:
Code: Select all
echo '<form action="admin.php?page=$Page&act=up" method="post">
<textarea rows="25" cols="100" name="html">$lines</textarea><input type="submit" value="Edit HTML">
</form>';
wouldn't be right, it would need to be something like:
Code: Select all
echo '<form action="admin.php?page='.$Page.'&act=up" method="post">
<textarea rows="25" cols="100" name="html">'.$lines.'</textarea><input type="submit" value="Edit HTML">
</form>';
But apart from that, it shouldn't be evaluating the fopen'd php code and i can't see a reason why it would do
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jun 20, 2004 6:39 pm
how about this
Code: Select all
<?php
if(is_readable($Page))
{
$lines = htmlentities(file_get_contents($Page),ENT_QUOTES);
echo "<form action="admin.php?page={$Page}&act=up" method="post"><textarea rows="25" cols="100" name="html">{$lines}</textarea><input type="submit" value="Edit HTML"></form>";
}
else
die($Page.' cannot be read.');
?>
Deemo
Forum Contributor
Posts: 418 Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC
Post
by Deemo » Sun Jun 20, 2004 6:55 pm
thank You very much feyd, that worked
@ mark: I accidently put it in single quotes cuz i copyed and pasted a trial that i did to make it work. d'oh
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Jun 20, 2004 7:00 pm
Sorry to go offtopic but:
Demo: Your sig i disagree with
semi-noobs best friend?
everytime I'm coding I always have my manual out with me... I can guarantee a lot of advanced users do aswell
Deemo
Forum Contributor
Posts: 418 Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC
Post
by Deemo » Sun Jun 20, 2004 8:01 pm
how about semi n00b and up lol
yeah i use that site more than anything