fopen file not updating inside textarea [fixed]

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

Post Reply
__autoload()
Forum Newbie
Posts: 7
Joined: Tue Jul 15, 2003 10:43 am

fopen file not updating inside textarea [fixed]

Post 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;
Last edited by __autoload() on Tue Jul 15, 2003 11:40 pm, edited 1 time in total.
__autoload()
Forum Newbie
Posts: 7
Joined: Tue Jul 15, 2003 10:43 am

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