S
sking623
I have been working on this for weeks. Whatever my FTP client does to
translate the unix text file with each line ending in a LF character
back into a LF CR I need some code in Perl to this.
The task is, save data from an html form into a flatfile database. I
have a Linux server. The program I have allows the user to search for a
text file (unix text) and download the file through their browser. It
has to convert the little LF's to CRLF. I have tried using some
people's suggestion on how to do this. But it doesn't work yet. Right
now it serves up the file because I have everything commented out! A
little messy, but the solution might be hiding in there! I just need to
know the right way to tweak it...
Any assistance is greatly appreciated.
Here's my code:
#!/usr/bin/perl
# This file is the one working
# This is called form the search page from option 1 in menu. You have
to login and search for a record.
# use a 1 to search for 1001.txt
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
my $file_location;
my $ID;
my @fileholder;
$subdirectory=param('subdirectory');
$ID = param('id');
$file_location = "../" . $subdirectory. "/" . $ID . "du.txt";
if ($ID eq '') {
print "Content-type: text/html\n\n";
print "You must specify a file to download.";
} else {
#open(FILE, "$file_location") || Error('open', 'file');
#binmode (FILE); # will read file as is (binary) it need to send
images
#@data=<FILE>;
#close FILE;
#print "Content-type: text/html\n\n";
#print $file_location;
#print @data;
#exit;
open(DLFILE, "<$file_location") || Error('open', 'file');
binmode -f(DLFILE);
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file');
#foreach $fileholder (@fileholder) {
#$fileholder =~ s|\012|\m\n|g;
#$fileholder =~ s|\012|$/|g;
#$fileholder = split(/\012/,$fileholder);
#}
#print "Content-type: text/html\n\n";
#foreach $fileholder (@fileholder) {
#print $fileholder;
#}
#exit;
open (LOG, ">>/home/mortga20/public_html/$subdirectory/log.txt") ||
Error('open', 'file');
print LOG "$ID\n";
close (LOG);
#print "Content-type:application/x-download\n"; #paste your type
#binmode STDOUT; # i not shure than need it
#print join(//, @data); # send client
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder
}
sub Error {
print "Content-type: text/html\n\n";
print "The server can't $_[0] the $_[1]: $! \n";
exit;
}
translate the unix text file with each line ending in a LF character
back into a LF CR I need some code in Perl to this.
The task is, save data from an html form into a flatfile database. I
have a Linux server. The program I have allows the user to search for a
text file (unix text) and download the file through their browser. It
has to convert the little LF's to CRLF. I have tried using some
people's suggestion on how to do this. But it doesn't work yet. Right
now it serves up the file because I have everything commented out! A
little messy, but the solution might be hiding in there! I just need to
know the right way to tweak it...
Any assistance is greatly appreciated.
Here's my code:
#!/usr/bin/perl
# This file is the one working
# This is called form the search page from option 1 in menu. You have
to login and search for a record.
# use a 1 to search for 1001.txt
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
my $file_location;
my $ID;
my @fileholder;
$subdirectory=param('subdirectory');
$ID = param('id');
$file_location = "../" . $subdirectory. "/" . $ID . "du.txt";
if ($ID eq '') {
print "Content-type: text/html\n\n";
print "You must specify a file to download.";
} else {
#open(FILE, "$file_location") || Error('open', 'file');
#binmode (FILE); # will read file as is (binary) it need to send
images
#@data=<FILE>;
#close FILE;
#print "Content-type: text/html\n\n";
#print $file_location;
#print @data;
#exit;
open(DLFILE, "<$file_location") || Error('open', 'file');
binmode -f(DLFILE);
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file');
#foreach $fileholder (@fileholder) {
#$fileholder =~ s|\012|\m\n|g;
#$fileholder =~ s|\012|$/|g;
#$fileholder = split(/\012/,$fileholder);
#}
#print "Content-type: text/html\n\n";
#foreach $fileholder (@fileholder) {
#print $fileholder;
#}
#exit;
open (LOG, ">>/home/mortga20/public_html/$subdirectory/log.txt") ||
Error('open', 'file');
print LOG "$ID\n";
close (LOG);
#print "Content-type:application/x-download\n"; #paste your type
#binmode STDOUT; # i not shure than need it
#print join(//, @data); # send client
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder
}
sub Error {
print "Content-type: text/html\n\n";
print "The server can't $_[0] the $_[1]: $! \n";
exit;
}