[Resolved] PHP editing a file

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch
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

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>
heres the css for textbox:
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%:
}
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Just tried it myself and I presume you mean the extra line at the top of the textarea?

If this is the case it is the html that is causing it replace the following lines :-

PHP:
                            <textarea name="savecontent" cols="80" rows="<?=$count;?>" class="textarea" >
                                <?php echo $loadcontent;?>
                            </textarea>

With the following line:-

PHP:
<textarea name="savecontent" cols="80" rows="<?=$count;?>" class="textarea" ><?php echo $loadcontent;?></textarea>
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back