Solved – 2nd ‘Bitesized’ GroundwaterGo programming opportunity
| April 17, 2012 | Posted by karmadsen under blog, GroundwaterGo |
As you may recall, the objective of the 2nd ‘Bitesized’ GroundwaterGo programming opportunity was to write a text editor window that could be used to modify MODFLOW files over the internet. This ticket has now been solved.
Here’s how the MODFLOW output window looks now:
The code involved in solving this problem is made up of two php/html files. The first file displays the text file for editing.
<?
$code=$_GET['code'];
$ext=$_GET['ext'];
$a_string = “http://174.129.29.197/maps/htdocs/temp_maps/models/mod”;
$nam_string = $a_string . $code . “.” . $ext;
$file_string = “mod” . $code . “.” . $ext;
$homepage = file_get_contents(“$nam_string”);
?><html>
<img src=”http://174.129.29.197/home/wp-content/uploads/2011/07/cropped-logo10.jpg” alt=”regular”/>
<body>
<form action=”myform.php” method=”post”>
<input type=”hidden” name=”file” value=”<? echo $file_string; ?>”>
<p>Edit File: mod<? echo $code; ?>.<? echo $ext; ?>
<br />
<input type=”submit” value=”Update”>
<br />
<TEXTAREA NAME=”text” COLS=80 ROWS=40><?php
echo $homepage;?></TEXTAREA>
</form>
</body>
</html>
The second file updates the original file, with new text.
<?
$myFile = $_POST['file'];
$fh = fopen($myFile, ‘w’) or die(“can’t open file”);
$stringData = $_POST['text'];
fwrite($fh, $stringData);
fclose($fh);
?><html>
<img src=”http://174.129.29.197/home/wp-content/uploads/2011/07/cropped-logo10.jpg” alt=”regular”/>
<body>
<br />
Your file has been updated.
</body>
</html>