View Single Post
  #10 (permalink)  
Old 12-15-09, 01:27 PM
beazleybub beazleybub is offline
Newbie Coder
 
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
This is the current save function based on your example from the open function.
Code:
<?php
$saving = $_REQUEST['saving'];
if ($saving == 1){ 
$data = $_POST['data'];
if (isset($_POST['source'])) 
  $file = $_POST['source'];  
else 
  $file='instructions.php';

$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!"); 

fclose($fp); 
$theMessage = "Saved!";
}
?>
This is the form that I have to choose the file to save to.
Code:
<form action="editor.php?saving=1" method="post" name="form">
	<textarea cols="100" name="data" rows="10">
<?php echo $theData;?>
</textarea>
<br><br>
<select name="source" size="1">
<option>data.php</option>
<option>data2.php</option>
</select>
<input type="submit" value="Choose Where To Save">
</form>
What I meant by me making things overly complicated was I now have two dropdown boxes, one for opening and one for saving. I would like to simplify it to one dropdown box that opens the file and remembers what file is open so when I click save it simply saves to the file that I opened from the dropdown box.

Here is the complete code.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>editor</title>

</head>

<body>

<?php
$saving = $_REQUEST['saving'];
if ($saving == 1){ 
$data = $_POST['data'];
if (isset($_POST['source'])) 
  $file = $_POST['source'];  
else 
  $file='instructions.php'; /* I will have to fix this to save to the file loaded somehow*/

$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fwrite($fp, $data) or die("Couldn't write values to file!"); 

fclose($fp); 
$theMessage = "Saved!";
}
?>

<?php
if (isset($_POST['source'])) 
  $myFile = $_POST['source'];  
else 
  $myFile='instructions.php'; 
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
?>

<div style="height:25px">
<?php echo $theMessage; ?>
</div>
<form name="myForm" method="post" action="editor.php">

<select name="source" size="1">
<option>data.php</option>
<option>data2.php</option>
</select>
<input type="submit" name="submit" value="Choose File To Edit">

</form>

<form action="editor.php?saving=1" method="post" name="form">
	<textarea cols="100" name="data" rows="10">
<?php echo $theData;?>
</textarea>
<br><br>
<select name="source" size="1">
<option>data.php</option>
<option>data2.php</option>
</select>
<input type="submit" value="Choose Where To Save">
</form>

</body>

</html>
I thought using a zip file would be easy for you that's why I did it that way.

Thanks
Reply With Quote