subhailc
09-23-2004, 12:00 PM
hi. the following works fine for the most part; it displays a textfile in a textarea and saves user changes onsubmit - i can get it to save to any of the three files i'm referencing, and can get it to display any single one of them, but i'm trying to get it to swap the contents of the textarea onchange of the selectbox - do i need js for this or can php react to an onchange event by itself?
i think i'm way overdoing this because of my inability - all i'm trying to do is allow a user to edit three text files stored serverside. i suspect there's a ridiculously easy way to do this that i'm just not aware of; if that's not the case i'd appreciate any direction as to how to accomplish what i'm trying with the below code.
the bit that's troublesome is red.
thanks.
<?php
$filename = ($selbx);
if($submit && $string){
$textfile= fopen($filename,'w+');
if(! $textfile){
exit;
}
fputs($textfile, $string);
fclose($textfile);
}
else{
?>
<form method=post action="<? echo $PHP_SELF; ?>" ?>
<select size=1 name=selbx>
<option value=1.txt>page1</option>
<option value=2.txt>page2</option>
<option value=3.txt>page3</option>
</select>
<textarea rows=10 cols=20 name=string>
<?php @readfile($selbx); ?>
</textarea>
<input type=submit name=submit value=write to file>
<?
}
?>
i think i'm way overdoing this because of my inability - all i'm trying to do is allow a user to edit three text files stored serverside. i suspect there's a ridiculously easy way to do this that i'm just not aware of; if that's not the case i'd appreciate any direction as to how to accomplish what i'm trying with the below code.
the bit that's troublesome is red.
thanks.
<?php
$filename = ($selbx);
if($submit && $string){
$textfile= fopen($filename,'w+');
if(! $textfile){
exit;
}
fputs($textfile, $string);
fclose($textfile);
}
else{
?>
<form method=post action="<? echo $PHP_SELF; ?>" ?>
<select size=1 name=selbx>
<option value=1.txt>page1</option>
<option value=2.txt>page2</option>
<option value=3.txt>page3</option>
</select>
<textarea rows=10 cols=20 name=string>
<?php @readfile($selbx); ?>
</textarea>
<input type=submit name=submit value=write to file>
<?
}
?>