I have a CGI script that compiles .TXT database info into a table. I'd like to add a link to the page that forces the user to save the .TXT file when they select the link. I'm sure I'm missing something terribly obvious, but forest and trees and all, I'm just not seeing it. Why can't I download my text file?!
Thanks so much,
Meghan
Script currently reads as follows:
Thanks so much,
Meghan
Script currently reads as follows:
Code:
#!/usr/bin/perl
require "cgi-lib.pl";
print &PrintHeader;
if (-e "lock.fil")
{
print &PrintHeader;
print <<"PrintTag";
<html>
<head>
<title>File in Use</title>
<style type="text/css">
h3 {color: red;}
</style>
</head>
<body>
<h3>Error!</h3>
<p>The database is in use. Please try again later.</p>
</body>
</html>
PrintTag
exit(0);
}
open(LOCK_FILE, ">lock.fil");
open(FILE,"cmaa.txt") || die "Can't find database\n";
@indata = <FILE>;
close(FILE);
close(LOCK_FILE);
unlink("lock.fil");
print <<"PrintTag";
<html>
<head>
<title>Sponsor Logic® CMAA Registration</title>
<style>
<!--
body, td {font-family: verdana, arial, sans-serif; font-size: 8pt;}
-->
</style>
</head>
<body >
<center>
<h3>Club Managers Association of America Registration</h3>
<table border=1 cellspacing=0 cellpadding=2>
<tr>
<td><b>First Name</b></td>
<td><b>Last Name</b></td>
<td><b>Company</b></td>
<td><b>State</b></td>
<td><b>Telephone</b></td>
<td><b>Email</b></td>
<td><b>Password</b></td>
<td><b>Password<br />Confirm</b></td>
</tr>
PrintTag
#Use a foreach loop to process each record in the database
foreach $i (@indata)
{
#Remove hard return from each record
chomp($i);
#Split fields on pipe character
#Assign a variable name to each of the fields
($fname,$lname,$co,$st,$tele,$email,$pwd1,$pwd2) = split(/\|/,$i);
#Add a new row to the table for each record
print "<tr>";
print "<td>$fname</td>";
print "<td>$lname</td>";
print "<td>$co</td>";
print "<td>$st</td>";
print "<td>$tele</td>";
print "<td><a href=\"mailto:$email\">$email</a></td>";
print "<td>$pwd1</td>";
print "<td>$pwd2</td>";
print "</tr>\n";
#Close the loop
}
print "<tr><td colspan=\"8\"><a href=\"cmaa.txt\">Right Click to Download Database</a></td></tr>";
#Close the table
print "</table>";
print "</center></body></html>";
#End of script