My Quick and dirty text file editor

If you have a program or script that you'd like to give away or sell, this is the place to do it. All offers should include contact info.

Moderators: BBear, theunknownhost, flaguy

Post Reply
User avatar
Arf
Official Test Penquin
Posts: 9103
Joined: Tue Apr 09, 2002 12:00 am
Location: IDAHO, USA
Contact:

My Quick and dirty text file editor

Post by Arf » Fri May 30, 2003 1:31 pm

If you're looking for a little web based interface for text file editing, for your config files, here ya go. It's designed to do a job, not look pretty. Note the text file will need to writeable by others so it's best to protect it and this program behind a password.

TextFileEditor.html

Code: Select all

<HTML>
<BODY>
<?php
// TextFileEditor by Thomas Leo 2003
// Edit the variables below to suit your needs. Be sure that the text file by the name of $TEXTFILENAME
// Exists before you try to edit it. You'll need to chmod that file go+w as well.

$TEXTFILENAME="/home/path/textfile.txt";
$HEADERCOLOR="0000FF";
$HEADER="Edit a text file";
$COLUMNS="80";
$ROWS="20";


//////////////////////////////////////////////////////////////////////////
// CHECK IF FORM WAS POSTED BY USER
//////////////////////////////////////////////////////////////////////////
        //if data was posted from form read the variables from PHP environment and write them to disk
        if ($REQUEST_METHOD == "POST")
        {
                // READ $HTTP_POST_VARS[] TO NEW TEXTFILE DATA
                $textlist = $_POST["textlist"];

                //WRITE the new textlist file
                // Write out info based on variables entered by user in form

                //echo $textlist;
                $textlistarray = explode("\n",$textlist);
                // Sort textlistarray
                sort($textlistarray);

                //Assemble the new textlist text, stripping off whitespace and adding a \n
    for($x=0; $x <= count($textlistarray); $x++)
    {
                        if (strlen($textlistarray[$x]) >= 3)
                                $NewText=$NewText . trim($textlistarray[$x]) . "\n";
    }
    $fh = fopen("$TEXTFILENAME", "w") OR die("ERROR: could not open file ($TEXTFILENAME)");
                fwrite($fh,"$NewText");
    fclose($fh);

        }

///////////////////////////////////////////////////////////////////////////////
//SHOW THE PAGE WITH DATA FROM $TEXTFILENAME
///////////////////////////////////////////////////////////////////////////////

    $fh = fopen("$TEXTFILENAME", "r") OR die("ERROR: could not open file ($TEXTFILENAME)");
    fclose($fh);

        // Read the $TEXTFILENAME file
        $textlist = file($TEXTFILENAME);

        // Starting of Form
        echo '<FORM METHOD="POST" ACTION="./maketextfile.php">';

        echo '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=3 WIDTH="95%" borderColor=#CCCCCC bgcolor="#DDDDDD" halign="CENTER">';
        echo '<TR>
                <TD><CENTER><font color=" ' .$HEADERCOLOR . '"> <B>' . $HEADER . '</B></font></CENTER>
                </TD>
                </TR><TR>
                <TD>';
        echo '<CENTER>Enter text below.<BR>';
  echo '<textarea name="textlist" cols="' . $COLUMNS . '" rows="' . $ROWS . '">';     
    for($x=0; $x <= count($textlist); $x++)
    {
      echo "$textlist[$x]";     
//      next($textlist);
    }
    echo '</textarea>';
        // show update button
        echo "<P>";
        echo "<INPUT TYPE=\"SUBMIT\" VALUE=\">>>>>>>>>>>>  Update Entries  <<<<<<<<<<<<<<   \">";
        echo "</P>";
        echo "</CENTER>";


        echo '</TD>
                </TR>
        </TABLE>';

        // Close the <FORM> tag
        echo "</FORM>";

//      phpinfo(INFO_VARIABLES);

echo 'TextFileEditor Copyright 2001-2003,
 Thomas Leo<a href="$TEXTFILENAME" target="_blank">.</a>
 Last Edit: ' . date("M j, Y", getlastmod());

?>
</BODY>
</HTML>

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest