in reply to Upload form

It looks to me its the way you are parsing your cgi. Try this upload script:
#!/usr/bin/perl use warnings; use strict; use CGI; use CGI::Carp 'fatalsToBrowser'; #my $maxsize = 1024 * 100; #max 100K my $maxsize = 1024 * 20000; #max 20M #$CGI::POST_MAX= $maxsize; # max 100K posts !not working right? #$CGI::DISABLE_UPLOADS = 1; # no uploads my $query = new CGI; my $upload_dir = "uploads"; #permissions for dir are set print $query->header(); if($ENV{CONTENT_LENGTH} > $maxsize){ print "file too large - must be less than $maxsize bytes"; exit; } my $file = $query->param("file"); my $filename = $file; $filename =~s/.*[\/\\](.*)/$1/; open (UPLOADFILE, ">$upload_dir/$filename"); $/= \8192; # sets 8192 byte buffer chunks, perldoc perlvar while ( <$file> ){ print UPLOADFILE $_; #select(undef,undef,undef,.05); #for testing } close UPLOADFILE; print <<END_HTML; <HTML> <HEAD> <TITLE>Thanks!</TITLE> </HEAD> <BODY bgcolor="#ffffff"><br> <P>Thanks for uploading file : $filename!</P> </BODY> </HTML> END_HTML
and a form
<html> <form enctype="multipart/form-data" method=post action=http://z.net/cg +i-bin/up1.cgi> <input type=file name=file > <INPUT TYPE="submit" VALUE="Send!"> + </form> </html>

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: Upload form
by JimJx (Beadle) on Feb 18, 2007 at 18:04 UTC
    Thank you, that worked.

    I do appreciate the time, but I am curious about why the contents of the file are returned when I use $input{UPLOAD} and select the file on the form when that field name is UPLOAD.

    That is going to drive me nuts until I figure it out.

    But again, thank you for taking the time to answer.
    Jim

      That is going to drive me nuts until I figure it out.

      My advice is to let it go for now, and just accept CGI.pm's way of doing it. A few years ago, after Perl5 came out, and CGI.pm, there was many posts here concerning the old manual-cgi-parsing, and the general wisdom is always use CGI.pm instead of the old Perl4 style manual input parsing. The question was asked so many times, that when anyone asked a cgi question that used manual parsing, they were answered simply with " use CGI.pm".

      So let it go. There are many tiny details, see manual parsing for an idea of the complexities. So just accept for now, as a definition, "always use CGI.pm". The common complaint about CGI.pm is that it is big and cumbersome, but you can just import the input parsing portion of it.... use CGI qw(:cgi), or check out CPAN for CGI::Simple and CGI::Lite.

      You will run into so many problems with manual parsing that it is a waste of time to learn it. For instance what happens when you have multiple files to upload, or you want to give a different name to the uploaded file on the receive end? Look at this nice example:

      #!/usr/bin/perl use warnings; use strict; use CGI::Simple; my $upload_dir='uploads'; my $q = new CGI::Simple; print $q->header(); my $files = $q->upload(); # number of files uploaded +; my @files = $q->upload(); # names of all uploaded fil +es my $filename = $q->param('upload_file'); # filename of uploaded fil +e my $mime = $q->upload_info($filename,'mime'); # MIME type of uploa +ded file my $size = $q->upload_info($filename,'size'); # size of uploaded f +ile # short and sweet upload my $ok = $q->upload( $q->param('upload_file'),"$upload_dir/$filename") +; print "Uploaded ".$q->param('upload_file')." and wrote it OK!\n" if $o +k; print "total files = $files<br> filenames = @files<br> filename = $filename<br> mimetype= $mime<br> size=$size<br>";

      I'm not really a human, but I play one on earth. Cogito ergo sum a bum
        Good advice, I will accept that, for now. ;-)

        But, I have always been the one that wanted to know things and not jst accept conventional wisdom because "that is the way we do things."

        But, when I have more time, I will probably delve deeper into it just for my own curiousity if for no other reason.

        Thanks,
        Jim