Page 1 of 1

fopen file not updating inside textarea [fixed]

Posted: Tue Jul 15, 2003 10:43 am
by __autoload()
The script's purpose is to show $_GET['filename'] inside a textarea, and when the submit button is clicked, the file is edited and the stuff in the textarea SHOULD appear with the updated file.

For some reason however, when edit is pressed the content in the textarea is not updated like I want it to be. It remains the same until I refresh the page.

Is there any way of fixing this behaviour?

Here's the rough code.

Code: Select all

function edit_file() {

 print '<form method=''POST''>';
 print 'Editing ./'.$_GET&#1111;'filename'].'<br>';
 print 'Content: <textarea name=''create_content'' style=''width:400px;height:300px;''>';
 $fpr = fopen('./'.$_GET&#1111;'filename'],'r');
 while (!feof($fpr))&#123;
 print fgetc($fpr);
 &#125;
 fclose($fpr);
 print '</textarea><br>';
 print '<input type=''submit'' value=''Create''>';
 print '</form>';

 if ($_GET&#1111;'filename'])&#123;
  if ($_POST&#1111;'create_content']) &#123;
   $fpw = fopen($_GET&#1111;'filename'],'w');
   fwrite($fpw,$_POST&#1111;'create_content']);
   fclose($fpw);
   print 'Content has been written into the file.<br>';
  &#125;
 &#125;
&#125;

Posted: Tue Jul 15, 2003 10:43 pm
by __autoload()
Never mind, I fixed it. It was a stupid mistake, the order of the functions were wrong, now that I see it its painfully obvious.

Code: Select all

function edit_file() &#123;

 if ($_GET&#1111;'filename'])&#123;
  if ($_POST&#1111;'create_content']) &#123;
   $fpw = fopen($_GET&#1111;'filename'],'w');
   fwrite($fpw,$_POST&#1111;'create_content']);
   fclose($fpw);
   print 'Content has been written into the file.<br>';
  &#125;
 &#125;

 print '<form method=''POST''>';
 print 'Editing ./'.$_GET&#1111;'filename'].'<br>';
 print 'Content: <textarea name=''create_content'' style=''width:400px;height:300px;''>';
 $fpr = fopen('./'.$_GET&#1111;'filename'],'r');
 while (!feof($fpr))&#123;
 print fgetc($fpr);
 &#125;
 fclose($fpr);
 print '</textarea><br>';
 print '<input type=''submit'' value=''Create''>';
 print '</form>';
&#125;