Fellow monks,
I am modifying a script to port it from *nix to IIs. All of the script is in good order as of today except for this file_upload sub. Can anyone advise me as to why I am getting the error: "Undefined subroutine CGI::upload" from this code?
TIA
jg
#!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw/fatalsToBrowser /; use CGI ':standard'; my $megabyte = 1024 * 1024; # bytes my $max_mb = 1; # max no. of MB we will allow $CGI::DISABLE_UPLOADS = 0; # CGI module variable for en/disabling uploads (non-zero to disable) $CGI::POST_MAX = $megabyte * $max_mb; # CGI module variable for maximum upload size (bytes) my $q = CGI->new(); my $base_dir = 'D:\\Inetpub\\thissite.org\\'; my $target_dir = "\\alerts\\images\\"; my $base_dom = "http://www.thissite.org/alerts"; my $image_folder="/images/";

The parsing code (not included) checks to see if the upload_file param is defined, and if it is it calls the sub below:

sub file_up { local $| = 1; my ($bytesread,$buffer,$file); my $directory = $base_dir . $target_dir; my $fh = $q->upload('upload_file'); binmode $fh; my $filename = $q->param('upload_file'); $filename =~ s/[^A-Za-z0-9\.\_]//g; open(OUTF, '>' . $directory . $filename); while ($bytesread = read($fh, $buffer, 1024)) { print(OUTF $buffer); } close(OUTF); if (!$file && $q->cgi_error) { print($q->header(-status=>$q->cgi_error)); exit 0; } $image_link = $base_dom . $image_folder . $filename; $image_link; }
_____________________________________________________
If it gets a little bit out of hand sometimes, don't let it fool you into thinkin' you don't care.TvZ

In reply to Undefined subroutine CGI::upload by jerrygarciuh

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.