- Impact
- 19
PHP editing a file
Hey
can anyone look at the code and tell me whats wrong? the php parts are working..for the most part..but the output is a little weid..the textbox is a little messed up..the first line of the file is spaced weirdly..and the line numbers are a little off...thanks
heres the css for textbox:
Hey
can anyone look at the code and tell me whats wrong? the php parts are working..for the most part..but the output is a little weid..the textbox is a little messed up..the first line of the file is spaced weirdly..and the line numbers are a little off...thanks
PHP:
<?php
$dir = htmlspecialchars(trim($_GET['dir']));
$subdir = htmlspecialchars(trim($_GET['subdir']));
$file = trim($_GET['file']);
$loadcontent="./$dir/$subdir/$file";
//$loadcontent = "./includes/template/style.css";
if(isset($_POST['save_file'])) {
$savecontent = stripslashes($_POST['savecontent']);
$fp = fopen($loadcontent, "w");
if ($fp) {
fwrite($fp, $savecontent);
fclose($fp);
//print '<a href='.$_SERVER[PHP_SELF].'>Refresh</a>';
//print "<html><head><META http-equiv=\"refresh\" content=\"0;URL=$_SERVER[PHP_SELF]\"></head><body>";
}
}
$fp = fopen($loadcontent, "r");
$loadcontent = fread($fp, filesize($loadcontent));
$lines = explode("\n", $loadcontent);
$count = count($lines);
$loadcontent = htmlspecialchars($loadcontent);
fclose($fp);
for ($a = 1; $a < $count+1; $a++) {
$line .= "$a\n";
}
?>
<table border='1' width="30%" align="center">
<tr>
<td>
<table>
<form method=post action="<?$_SERVER['REQUEST_URI']?>">
<tr>
<td width="5%" align="right" valign="top"></td><td><input type="submit" name="save_file" value="Save" class="button"></td>
</tr>
<tr>
<td width="5%" align="left" valign="top">
<pre name="lines" cols="4" rows="<?=$count+3;?>"><?=$line;?></pre>
</td>
<td width="95%" align="right" valign="top">
<textarea name="savecontent" cols="80" rows="<?=$count;?>" class="textarea" >
<?php echo $loadcontent;?>
</textarea>
</td>
</tr>
<tr>
<td width="5%" align="right" valign="top"></td><td><input type="submit" name="save_file" value="Save" class="button"></td>
</tr>
</form>
</table>
</td>
</tr>
</table>
Code:
.textarea {
background: #a3bed9;
color: #252525;
font-family: Tahoma;
font-size: 11px;
border-width: 1px;
border-color: #373737;
border-style: dashed;
width: 100%
height: 100%:
}