Completing Construction of a Database Form with HTML - Cgi-bin Directory
(Page 5 of 6 )
Create a directory called cgi-bin in the highest directory of your site. Copy the code below into your text editor, and save the resulting file in the cgi-bin directory; name the file receiveData.pl. This is the code:
use CGI;
$cgi = new CGI;
$error = $cgi->cgi_error;
open DESTINATION, ">store.txt";
$cgi->save(DESTINATION);
close DESTINATION;
$filename0 = $cgi->upload('Pi03');
$path0 = ">";
open (OUTFILE,$path0);
while ($bytesread=read($filename0,$buffer,1024))
{
print OUTFILE $buffer;
}
close OUTFILE;
$filename1 = $cgi->upload('Pi13');
$path1 = ">";
open (OUTFILE,$path1);
while ($bytesread=read($filename1,$buffer,1024))
{
print OUTFILE $buffer;
}
close OUTFILE;
$filename2 = $cgi->upload('Pi23');
$path2 = ">";
open (OUTFILE,$path2);
while ($bytesread=read($filename2,$buffer,1024))
{
print OUTFILE $buffer;
}
close OUTFILE;
$filename3 = $cgi->upload('Pi33');
$path3 = ">";
open (OUTFILE,$path3);
while ($bytesread=read($filename3,$buffer,1024))
{
print OUTFILE $buffer;
}
close OUTFILE;
$filename4 = $cgi->upload('Pi43');
$path4 = ">";
open (OUTFILE,$path4);
while ($bytesread=read($filename4,$buffer,1024))
{
print OUTFILE $buffer;
}
close OUTFILE;
if ($error)
{
print $cgi->header(-status=>$error),
$cgi->start_html('Problems'),
$cgi->h2('Request not processed'),
$cgi->strong($error);
exit 0;
}
else
{
print "Content-Type: text/htmlnn";
print "<HTML>n";
print "<HEAD>n";
print "<TITLE>Thanks</TITLE>n";
print "</HEAD>n";
print "<BODY>n";
print "<H1>Thank You</H1>n";
print "<H2>Your message has been sent</H2>n";
print "</BODY>n";
print "</HTML>n";
}
If you are using a Unix, Linux or similar operating system, then precede the above code with the line:
#!/usr/local/bin/perl
which is the path to your Perl interpreter (modify it if necessary).
When you are through, open the web page and link the five image files to the five Input File controls of the web page (using the corresponding Browse buttons). Click the Save button. A new web page should appear, telling you that your message has been received.
Now open the cgi-bin directory. You should see a file called “store.txt.” This file has been created by the receiveData.pl program, which received the data. You should also see five other files, which represent the five different images; more on these later.
Next: Brief Explanation of the Web Page Code >>
More HTML Articles
More By Chrysanthus Forcha