csuhockey3 has asked for the wisdom of the Perl Monks concerning the following question:
failure ( 171): for host ***.***.**.*** trying to POST /cgi-bin/upload +.cgi, cgi_scan_headers reports: HTTP4044: the CGI program /cgi-bin/up +load.cgi did not produce a valid header (program termindated without +a vaild CGI header.
my $IN = $upload_path . param('excel') . ".txt"; exec "chmod 775 $IN"; my $OUT = "master.xml"; exec "chmod 775 master.xml";
#!/usr/bin/perl use strict; use warnings; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); $CGI::POST_MAX = 2097152; ## (2mb upload max) $CGI::DISABLE_UPLOADS = 0; ## allow uploads my $upload_path = "/export/"; my $filename = $upload_path . param('excel'); sub print_header { my $title = shift; print header, start_html($title); } sub init { my $upload = upload('excel'); unless (param('excel')) { print_header ('Excel to XML Converter'); print_upload_form(); ## make sure there's actually something being uploaded } elsif (!$upload && cgi_error) { print_header ('Excel to XML Converter: Error!'); print h1("No file uploaded!"); ## all is well, show conversion confirmation } else { show_convert(); } } sub print_upload_form { print h1('Upload Excel File.'), start_multipart_form(), "Excel file:", filefield( -name=>'excel' ), br, submit( -name=>"Convert" ), end_form; } ## show the conversion process sub show_convert { print header, start_html ("Converting..."), "Converting...<br />", $filename, br, convert(), "<br />Done!"; } sub convert { ## convert to the xSV file... my $fh = upload('excel'); my $bytes_read = -s $fh; open OUTFILE, '>', $filename or die "Couldn't open output file: $!\n"; while ( my $bytes = read($fh, my $buffer, 2097152)) { print OUTFILE $buffer; } close OUTFILE; ## convert to xSV... txt_to_xSV(); ## convert xSV to XML... xSV_to_XML(); ## copy/back up file, not added yet "Received $bytes_read bytes<br />"; } sub txt_to_xSV { require Spreadsheet::ParseExcel; my $oExcel = new Spreadsheet::ParseExcel; my $dir = $ARGV[1]; chomp $dir; unless (-d $dir) { print "Can't find directory $dir"; exit; } my $filename = "$dir/$ARGV[0]"; chomp $filename; unless (-e $filename) { print "Can't find file $filename"; exit ; } my $fullfilename = "$filename.txt"; ## start work #1.1 Normal Excel97 open E2T, ">", $fullfilename or die $!; my $oBook = Spreadsheet::ParseExcel::Workbook->Parse($filename); my($iR, $iC, $oWkS, $oWkC); foreach my $oWkS (@{$oBook->{Worksheet}}) { print "--------- SHEET:", $oWkS->{Name}, "\n"; print E2T $oWkS->{Name}, "|"; next unless defined $oWkS->{MinRow} and defined $oWkS->{MaxRow}; for my $iR ($oWkS->{MinRow} .. $oWkS->{MaxRow}) { for my $iC ($oWkS->{MinCol} .. $oWkS->{MaxCol}) { $oWkC = $oWkS->{Cells}[$iR][$iC]; next if ! defined $oWkC; print "( $iR , $iC ) =>", $oWkC->Value, "\n" if($oWkC); print E2T $oWkC->Value, "|"; } } print E2T "\n"; } close E2T; } sub xSV_to_XML { my $IN = "master.xls.txt"; my $OUT = "master.xml"; open (OUT, ">$OUT"); open(IN) or die ("Cannot open file ($IN)"); print OUT <<TOP; <?xml version="1.0" encoding="ISO-8859-1"?> TOP my $id = 0; my @columns = ("category","code","title","summary","prereq","group","subgroup","sequ +ence","rolemandatory","rolerecommended","roleoptional","url","modalit +y","length"); foreach my $row (<IN>){ $row =~ s#\s+$##; $row =~ s#&+#&#g; $row =~ s#(?<=\|)\|#0|#g; my ($category,$code,$title,$summary,$prereq,$group,$subgroup,$sequence,$r +olemandatory,$rolerecommended,$roleoptional,$url,$modality,$length) = split ('\|', $row); #will ignore lank next if $group eq ""; foreach $_ (@columns){ xmlrow($_); } print OUT "</star:course>\n"; $id++; } print OUT "</star:learning-paths>\n"; } sub xmlrow{ my $colname = shift(@_); my $ostar="<star:"; my $estar="</star:"; print OUT "<star:$colname>${$colname}</star:$colname>\n"; } init();
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: CGI valid header error
by dorko (Prior) on Feb 15, 2007 at 02:21 UTC | |
Re: CGI valid header error
by f00li5h (Chaplain) on Feb 15, 2007 at 02:49 UTC | |
by csuhockey3 (Curate) on Feb 15, 2007 at 02:54 UTC | |
by GrandFather (Saint) on Feb 15, 2007 at 03:01 UTC | |
by csuhockey3 (Curate) on Feb 15, 2007 at 03:15 UTC | |
by GrandFather (Saint) on Feb 15, 2007 at 03:25 UTC | |
Re: CGI valid header error
by Mr. Muskrat (Canon) on Feb 15, 2007 at 22:17 UTC |