I'm trying to write a CGI that accepts a file upload. I'm about to go totally nuts. Some helpful help would be appreciated.

Why am I going nuts, you ask? Why not use CGI.pm's handy upload() feature? Simple. That feature doesn't start until 2.47. I get 2.36. Before anyone says "install the new version" or "get them to install the new version" or even "install the new version in your directory": I can't. I've already asked the sysadmin to install it, but can't wait that long. I only have FTP access, so I'm not sure how to install through FTP. Thus, my request for some helpful help.

So, this is the code I have.
#!/usr/bin/perl -w use strict; use CGI qw(:standard); my $query = new CGI; print header; print start_html; my $user = $query->param('user'); my $password = $query->param('password'); { no strict; $filename = $query->param('foofile'); undef $/; $buffer = <$filename>; $buffer =~ tr/\r\n/\n/; @buffer= split /\n/, $buffer; } print $buffer[0]; print end_html;
This is the minim case, and it fails. Why? I have no idea. Apparently, I don't get CGI::Carp, either.

The undef $/; and tr bits are there for nasty file conversion issues.

Basically what seems to be happening is that @buffer is not global, so I can't see it outside that no strict; block. So I tried to put in, before that block, a my @buffer; line. That fails too.

I thought about trying to wade through CGI.pm and cut-n-pasting some code, but I'm kind of in a time crunch, and this almost works. :sigh:


In reply to CGI Upload with OLD CGI.pm by amelinda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.