hello,
I wrote a perl script to down load files from my website (I pieced it together from what i found on the net). the script does three things: opens a save as... dialog box for selecting destination, updates a log txt file and then writes a thank you html page. the problem is that when I click save on the dialog box it saves OK but then adds the html code to the end of the file rather than sending the html code to the browser. here is my script:
Thanks,
Michael
#!/usr/bin/perl -w
use CGI qw
standard);
&download_data;
&update_txt;
&print_thankyou;
#----------------------------------------------------------------------------
sub download_data
{
# location of folder on server computer where file will be uploaded to
$files_location= "/home/ cad 13d";
$query = new CGI;
# get name and path to file on local computer
$ID = $query->param("AvailableFiles");
open(DLFILE, "<$files_location/$ID");
@fileholder = <DLFILE>;
close (DLFILE);
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder
}
#----------------------------------------------------------------------------
sub update_txt
# remove downloaded file name from availablefiles.txt
{
# copy available.txt into @file_list array variable
open(AVAILABLE_LIST, "availablefiles.txt");
while(<AVAILABLE_LIST>)
{
push(@file_list, $_);
}
close(AVAILABLE_LIST);
# read through each line of the @file_list
# write each line back to the txt file if
# the line is not the downloaded filename ($ID).
# i.e. remove the downloaded filename from the availablefiles.txt
open(AVAILABLE_LIST, ">./availablefiles.txt");
foreach $line (@file_list)
{
if($line !~ $ID)
{
print AVAILABLE_LIST $line;
}
}
close(AVAILABLE_LIST);
# add downloaded file name to unavailable.txt file
open(UNAVAILABLE_LIST, ">>unavailablefiles.txt");
print UNAVAILABLE_LIST "$ID\n";
close(UNAVAILABLE_LIST);
}
#----------------------------------------------------------------------------
sub print_thankyou
{
print header;
#print "Content-type: text/html\n Window-target: _top\n\n";
print <<END_HTML;
<HTML>
<HEAD>
<TITLE>Thanks!</TITLE>
<META HTTP-EQUIV="Refresh" CONTENT="5; URL=http://notcher.freehostia.com/safesource.cgi">
</HEAD>
<BODY>
<P>Thanks for downloading your file!</P>
You will be redirected to the front page in 5 seconds, or<BR>
you can select this link: <A HREF="
</BODY>
</HTML>
END_HTML
}
#----------------------------------------------------------------------------
I wrote a perl script to down load files from my website (I pieced it together from what i found on the net). the script does three things: opens a save as... dialog box for selecting destination, updates a log txt file and then writes a thank you html page. the problem is that when I click save on the dialog box it saves OK but then adds the html code to the end of the file rather than sending the html code to the browser. here is my script:
Thanks,
Michael
#!/usr/bin/perl -w
use CGI qw
&download_data;
&update_txt;
&print_thankyou;
#----------------------------------------------------------------------------
sub download_data
{
# location of folder on server computer where file will be uploaded to
$files_location= "/home/ cad 13d";
$query = new CGI;
# get name and path to file on local computer
$ID = $query->param("AvailableFiles");
open(DLFILE, "<$files_location/$ID");
@fileholder = <DLFILE>;
close (DLFILE);
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder
}
#----------------------------------------------------------------------------
sub update_txt
# remove downloaded file name from availablefiles.txt
{
# copy available.txt into @file_list array variable
open(AVAILABLE_LIST, "availablefiles.txt");
while(<AVAILABLE_LIST>)
{
push(@file_list, $_);
}
close(AVAILABLE_LIST);
# read through each line of the @file_list
# write each line back to the txt file if
# the line is not the downloaded filename ($ID).
# i.e. remove the downloaded filename from the availablefiles.txt
open(AVAILABLE_LIST, ">./availablefiles.txt");
foreach $line (@file_list)
{
if($line !~ $ID)
{
print AVAILABLE_LIST $line;
}
}
close(AVAILABLE_LIST);
# add downloaded file name to unavailable.txt file
open(UNAVAILABLE_LIST, ">>unavailablefiles.txt");
print UNAVAILABLE_LIST "$ID\n";
close(UNAVAILABLE_LIST);
}
#----------------------------------------------------------------------------
sub print_thankyou
{
print header;
#print "Content-type: text/html\n Window-target: _top\n\n";
print <<END_HTML;
<HTML>
<HEAD>
<TITLE>Thanks!</TITLE>
<META HTTP-EQUIV="Refresh" CONTENT="5; URL=http://notcher.freehostia.com/safesource.cgi">
</HEAD>
<BODY>
<P>Thanks for downloading your file!</P>
You will be redirected to the front page in 5 seconds, or<BR>
you can select this link: <A HREF="
</BODY>
</HTML>
END_HTML
}
#----------------------------------------------------------------------------