> -----Original Message-----
> From: Pedro A Reche Gallardo [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, December 08, 2001 3:06 PM
> To: [EMAIL PROTECTED]
> Subject: help with form
> 
> 
> Hi all,   I am working on a cgi script that can create  a 
> temporal file
> with either an uploaded file, or, in its absence,  the pasted 
> content of
> that file.  I have managed to upload the file only if that is the only
> input field in my form, but if I add  the choice to paste the 
> content of
> the file, there is no way I can successfully create the temporal file
> with the content of the uploaded file.   I am including with 
> this e-mail
> the html code of the form I am using together with the cgi script I am
> working on, and I will be very happy if someone could let me know why
> this thing is not working.
> Thanks.
> 
> Pedro
> 
> HTML
> <html>
> <head>
> <html>
> <head>
>    <title>test</title>
> </head>
> </head>
> <body bgcolor="#FFFFCD" link="#0000FF">
> <center>
> <h1>
> <font size=+4>TEST</font></h1></center>
> <p><br>
> <p>
> <hr size="2" NOSHADE>
> <br><form  method="POST" action="../../cgi-bin/variab.cgi"
> enctype="multiform/fo
> rm-data">

enctype should be "multipart/form-data", not "multiform/form-data"

> <table BORDER=2 >
> <tr><td>
>         <p><b>Enter a name for your  file:<br></b>
>         <INPUT SIZE=25 NAME="name">
>         </p>
> </td></tr>
> <tr><td><p></p></td></tr>
> <tr><td>
> <p> <b>Upload your file</b><br>
> <input type="file" name="file"  SIZE=30>
> </p></td></tr>
> <tr><td><p></p></td></tr>
> <tr><td>
> <p><b>Paste the content of your file</b>
> <textarea NAME="alignment" ROWS=10 COLS=80></textarea>
> </td></tr></p>
> </table>
> </form>
> <P><hr size="4">
> </body>
> </html>
> 
> CGI
> #!/usr/sbin/perl -wT
> use CGI;
> use strict;
> use Fcntl qw( :DEFAULT :flock);
> #define file paths for file writes and genscan location
> 
> 
> my $bin="/usr1/par/bin";
> my $httproot = "/usr/freeware/apache/share/htdocs/MIF/icons/";
> my $dir = "/tmp/"; #directory for writing files
> my $gnuplot = "/usr/freeware/bin/gnuplot";
> my $ppmtogif = "/usr/freeware/bin/ppmtogif";
> 
> 
> my $q = new CGI;
> print $q->header,  $q->start_html(-title=>"Variability
> Results",-bgcolor=>"white");
> print $q->h1("Variability Results");
> 
> 
> my $in    = $q->param("name");
> my $file  = $q->param("file");
> my $fh    = $q->upload( $file );

Use $q->upload('file')

> my $paste = $q->param("alignment");
> my $i;
> my $flen;
> 
> my $var = $^T;
> $in =~ s/\s\t//g;
> $in = $in.$var;
> 
> 
> if (!$file) {
>   open(INFILE, ">$dir/$in") || die "I cannot create $in!\n";

$in is tainted, so this will fail.

>   flock(INFILE, 2);
>   print INFILE "$paste";
>   close (INFILE) || die "can't close $dir/$in!";
> } else {
>   open(UPLOAD,">$dir/$in") or die "Can't open outfile for 

$in is tainted, so this will fail.

> writing: $!";
>   $flen = 0;
>   while (read($fh,$i,1024)) {
>       print UPLOAD $i;
>       $flen = $flen + 1024;
>       if ($flen > 5120000) {

Use $CGI::POST_MAX to limit post size.

>       close(UPLOAD);
>       die "Error - file is too large. Save aborted.<p>";
>       }
>      }
> close(UPLOAD);
> }
> 
> $q->end_html;
> 
> **************************************************************
> *************
> 
> PEDRO A. RECHE , pHD             TL: 617 632 3824
> Dana-Farber Cancer Institute,    FX: 617 632 4569
> Harvard Medical School,          EM: [EMAIL PROTECTED]
> 44 Binney Street, D1510A,        EM: [EMAIL PROTECTED]
> Boston, MA 02115                 URL: http://www.reche.org
> **************************************************************
> *************
> 
> 
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to