NameSilo

Simple code help

Spaceship Spaceship
Watch
Impact
19
Hey
I need a simple code tht does this

OKay so i have this file called nav.txt

Now i want to make a page where i can edit nav.txt ONLINE

so i need a code
tht first displays wts on nav.txt in a text area

and then a SAVE button below it
so the user can edit w.e they want in the text area and then when they press SAVE...it saves the file :)
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Something like this would probably work:

PHP:
<?php
$loadcontent = "nav.txt";
    if($save_file) {
        $savecontent = stripslashes($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";
}
?>
<form method=post action="<?=$_SERVER[PHP_SELF]?>">
<input type="submit" name="save_file" value="Save">
<table width="100%" valign="top" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="3%" align="right" valign="top">
<pre name="lines" cols="4" rows="<?=$count+3;?>"><?=$line;?></pre>
</td>
<td width="97%" align="left" valign="top">
<textarea name="savecontent" cols="150" rows="<?=$count;?>" wrap="OFF">
<?=$loadcontent?>
</textarea>
</td>
</tr>
</table>

<br>
<input type="submit" name="save_file" value="Save">
</form>
 
0
•••
Wow... NICE! That's very useful! Will it work with html files as well?

SecondVersion said:
Something like this would probably work:

PHP:
<?php
$loadcontent = "nav.txt";
    if($save_file) {
        $savecontent = stripslashes($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";
}
?>
<form method=post action="<?=$_SERVER[PHP_SELF]?>">
<input type="submit" name="save_file" value="Save">
<table width="100%" valign="top" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="3%" align="right" valign="top">
<pre name="lines" cols="4" rows="<?=$count+3;?>"><?=$line;?></pre>
</td>
<td width="97%" align="left" valign="top">
<textarea name="savecontent" cols="150" rows="<?=$count;?>" wrap="OFF">
<?=$loadcontent?>
</textarea>
</td>
</tr>
</table>

<br>
<input type="submit" name="save_file" value="Save">
</form>
 
0
•••
thats a really useful script
 
0
•••
Thanks second :) that was really really really helpfull :D
Can you please guide me to a website where i can find fopen kinda help..{file tutorials with php...tht teachs u stuff like the script u gave me :P}
Thanks
 
0
•••
Gene said:
Wow... NICE! That's very useful! Will it work with html files as well?
Yes, it will work with html files. Pretty much any file as long as it's writable, of course.

unknowngiver said:
Thanks second :) that was really really really helpfull :D
Can you please guide me to a website where i can find fopen kinda help..{file tutorials with php...tht teachs u stuff like the script u gave me :P}
Thanks
One of the best places to learn php.net ;)

http://us2.php.net/function.fopen Start there ;)
 
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back