[vox-tech] reading files into a web page (long scripts)

Eric Engelhard vox-tech@lists.lugod.org
Sat, 02 Feb 2002 10:29:14 -0800


Peter Jay Salzman wrote:
[snip]
> how can i do this?  i *think* php can do this, but i don't know a lick
> of php.  can someone give me explicit instructions on how to do this
> sort of thing?
> 
> if it makes a difference, i'm putting a form on the same page that adds
> text to /www/pcgm/bulletins.

Hi Pete,

I like to place content in a postgres database as a binary large objects
(blobs). http://www.cvbig.org/others/ is a an example of multiple blob
calls for both layout and content.

<?PHP
        echo "<html><body><title>CVBIG | Other SIGs</title>";
        $conn = pg_connect("dbname=cvbig port=5432");

        #header from db
        pg_Exec($conn, "BEGIN");
        $oid_result = pg_Exec($conn, "SELECT header FROM layout");
        $oid = pg_Result($oid_result, 0, "header");
        $handle = pg_loopen($conn, $oid, "r");
        $text = pg_loread($handle, 100000);
        $text = preg_replace("/\\\/","", $text);
        echo "$text";
        pg_Exec($conn, "COMMIT");
 
        #grab sig list from local_sigs and display
        $result = pg_Exec($conn, "SELECT * FROM local_sigs ORDER BY
NAME");
        $num_rows = pg_numrows($result);
        echo "<P><b>We are not alone!</b></p><p>Here are some local
interest groups worth visiting.</p><p>";
        while ($i<$num_rows){
                $group = pg_Result($result, $i, "name");
                $link = pg_Result($result, $i, "link");
                $description = pg_Result($result, $i, "description");
                echo "<p><a href=$link>$group</a>:<br>$description</p>";
                $i++;
        }
 
 
        #footer from db
        pg_Exec($conn, "BEGIN");
        $oid_result = pg_Exec($conn, "SELECT footer FROM layout");
        $oid = pg_Result($oid_result, 0, "footer");
        $handle = pg_loopen($conn, $oid, "r");
        $text = pg_loread($handle, 100000);
        $text = preg_replace("/\\\/","", $text);
        echo "$text";
        pg_Exec($conn, "COMMIT");
 
        echo "</body></html>";
?>

I have another page to add, edit, or delete content. This can easily be
altered for a bulletin board.

<html>
<title>Admin: Local Sigs</title>
<body background="../Texture_lt_gray_004.jpg">
<H2>Admin: Local Sigs</H2>
<?PHP
        $current_date = date("m-d-Y");
        echo "User <b>".getenv(Remote_User)."</b> logged on from
".getenv(Remote_Addr)." on ".$current_date."<
br>";
        $user_id = getenv(Remote_User);
        $conn = pg_connect("dbname=cvbig port=5432");
        function mylink(){echo "<a
href=http://www.cvbig.org/admin/>Administration Page</a>";}

        if (!$SUBMIT && !$ADD && !$NEW_SUBMIT){
                echo "Edit any or all of the following fields or add a
new entry.<br><br>";
                $query = pg_Exec($conn, "SELECT * FROM local_sigs ORDER
BY name");
                $num_rows = pg_numrows($query);
                while ($i< $num_rows){
                        $name = pg_Result($query, $i, 'name');
                        $link = pg_Result($query, $i, 'link');
                        $description = pg_Result($query, $i,
'description');
                        echo "<form enctype=multipart/form-data
action=local_sigs.php method=post>";
                        echo "<input type=hidden name=OLDNAME
value=$name>";
                        echo "SIG:<br><TEXTAREA COLS=50 ROWS=1
NAME=NAME>$name</textarea><br>";
                        echo "Link:<br><TEXTAREA COLS=50 ROWS=1
NAME=LINK>$link</textarea><br>";
                        echo "Description:<br><TEXTAREA COLS=100 ROWS=5
WRAP=VIRTUAL NAME=DESCRIPTION>$descrip
tion</textarea><br>";
                        echo "<input type=submit name=SUBMIT
value=submit-$name>";
                        echo "</form>";
                        $i++;
                }
                echo "<form enctype=multipart/form-data
action=local_sigs.php method=post>";
                echo "<input type=submit name=ADD value=add><br><br>";
                echo "</form>";
                mylink();
                exit;
        }
        if (!$SUBMIT && $ADD){
                echo "<form enctype=multipart/form-data
action=local_sigs.php method=post>";
                echo "SIG:<br><TEXTAREA COLS=50 ROWS=1
NAME=NAME></textarea><br>";
                echo "Link:<br><TEXTAREA COLS=50 ROWS=1
NAME=LINK></textarea><br>";
                echo "Description:<br><TEXTAREA COLS=100 ROWS=5
WRAP=VIRTUAL NAME=DESCRIPTION></textarea><br>"
;
                echo "<input type=submit name=NEW_SUBMIT value=submit>";
                echo "</form>";
                mylink();
                exit;
        }

        if ($SUBMIT){
 
                #display new values
                echo "The database has been updated with the following
values:<br><br>";
                $query = pg_Exec($conn, "SELECT * FROM local_sigs WHERE
name = '$NAME'");
                $name = pg_Result($query, 0, 'name');
                $link = pg_Result($query, 0, 'link');
                $description = pg_Result($query, 0, 'description');
                echo "<b>Name:</b> $name<br>";
                echo "<b>Link:</b> $link<br>";
                echo "<b>Description:</b><br><TEXTAREA COLS=100 ROWS=5
WRAP=VIRTUAL NAME=DESCRIPTION>$description</TEXTAREA><br>";
                mylink();
                exit;
        }
        if ($NEW_SUBMIT){
                #insert text
                $insert = pg_Exec($conn, "INSERT INTO local_sigs
(name,link,description) VALUES ('$NAME','$LINK','$DESCRIPTION')");
 
                #display new values
                echo "The following values have been inserted in the
database:<br><br>";
                $query = pg_Exec($conn, "SELECT * FROM local_sigs WHERE
name = '$NAME'");
                $name = pg_Result($query, 0, 'name');
                $link = pg_Result($query, 0, 'link');
                $description = pg_Result($query, 0, 'description');
                echo "<b>Name:</b> $name<br>";
                echo "<b>Link:</b> $link<br>";
                echo "<b>Description:</b><br><TEXTAREA COLS=100 ROWS=5
WRAP=VIRTUAL NAME=DESCRIPTION>$description</TEXTAREA><br>";
                mylink();
                exit;
        }
?>
</body>
</html>