Beefy Boxes and Bandwidth Generously Provided by pair Networks Russ
XP is just a number

Undefined subroutine CGI::upload

by jerrygarciuh (Curate)
on Sep 30, 2003 at 16:44 UTC ( #295339=perlquestion: print w/ replies, xml ) Need Help??
jerrygarciuh has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

I got roped into coding some stuff for a IIs box, bleah. My normal file upload routine is getting the error

Undefined subroutine CGI::upload

The eversion for CGI is 2.46 but from reading the revision history it does not appear that should be the issue. I can't get the folks running the box to answer any questions so far.

Anyone have any advice? Code is below.

#!/usr/local/bin/perl -w use strict; use CGI::Carp qw/fatalsToBrowser /; use CGI qw/:standard /; my $q = CGI->new(); my $user_pass = $q->param('pass'); my $target_directory = "c:\\rediculousIIsServer\\yata"; if ($user_pass eq 'somePass') { file_up(); } else { print $q->header, start_html, h2('Bad Password=', $user_pass); exit; } sub file_up { my $corrected_filename = $q->param('temp_filename'); $corrected_filename =~ s/ /_/g; local $| = 1; my ($bytesread,$buffer,$file); my $fh = $q->upload('temp_filename'); open(OUTF, '>' . $target_directory . $corrected_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; } my $redir = ""; print $q->redirect("$redir"); }
"The man who grasps principles can successfully select his own methods.
The man who tries methods, ignoring principles, is sure to have trouble.
~ Ralph Waldo Emerson

Comment on Undefined subroutine CGI::upload
Download Code
Re: Undefined subroutine CGI::upload
by dws (Chancellor) on Sep 30, 2003 at 16:48 UTC
    Try changing   use CGI qw/:standard /;
    to   use CGI qw/:all/;
    That might be overkill, but it does the job for me.

      Thanks for the reply dws. Unfortunately the error continues with use CGI qw/:all/;
Re: Undefined subroutine CGI::upload
by dragonchild (Archbishop) on Sep 30, 2003 at 16:48 UTC
    Try recoding to only use the OO interface and change your use line to use CGI;. I remember reading that you shouldn't mix procedural and OO interfaces, though I'm not sure why.

    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      I remember reading that you shouldn't mix procedural and OO interfaces, though I'm not sure why.

      Let's avoid the possibility of Cargo-Cult memes by supplying an actual reason. ;-)

      One reason is that when you mix the two interfaces you generally get 2 CGI objects. If data came back in a POST, only one will have the form data, leading to rather confusing results.

Re: Undefined subroutine CGI::upload
by matthewb (Deacon) on Sep 30, 2003 at 16:54 UTC
    The eversion for CGI is 2.46...

    From perldoc CGI:

    To be safe, use the upload() function (new in version 2.47).  
    When called with the name of an upload field, upload() 
    returns a filehandle, or undef if the parameter is not a 
    valid filehandle.
    Also, you don't need to import :standard if you are using the OO interface.

      Well that solves that, eh?

      Apparently my reading of the revision history was less than thorough!

      Thank you very much for catching that matthewb!


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://295339]
Approved by VSarkiss
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2014-04-19 06:13 GMT
Find Nodes?
    Voting Booth?

    April first is:

    Results (478 votes), past polls