Kiko has asked for the wisdom of the Perl Monks concerning the following question:

I'm getting this error: Undefined subroutine &main::error called at E:\Inetpub\scripts\bis\mkrdb\upload_files.pl line 83 in this portion of the script:
# This will create the new file in the new location until ( sysopen OUTFILE, UPLOAD_DIR . $uploadedfile, O_RDWR|O_CREAT|O_ +EXCL, 0777 ) { $uploadedfile =~ s/(\d*)(\.\w+)$/($1||0) + 1 . $2/e; $1 >= MAX_OPEN_TRIES and error( $grab_file, "Unable to save your f +ile. File 1" ); }
I had this script running on a developement box under apache and it worked just fine. Now i moved it to a production server and using IIS 5.0 and its not working. Here is the entire upload portion of the script:
UPLOAD_FILE: { for my $file_num (1..5) { my $file = $grab_file->param("file$file_num") or next UPLOAD_F +ILE; my ($base,$path,$type)=@_; my $file_handle = $grab_file->upload("file$file_num"); my $buffer = ""; if (!$file && $grab_file->cgi_error) { print $grab_file->header(-status=>$grab_file->cgi_error); exit 0; } if ($file) { $file =~ s/</&lt;/g; $file =~ s/>/&gt;/g; fileparse_set_fstype("MSWin32"); ($base,$path,$type) = fileparse($file,'\..*'); my $type = lc $type; my $uploadedfile = $base . $type; $uploadedfile =~ s/[^\w.-]/_/g; if ( $uploadedfile =~ /^(\w[\w.-]*)/ ) { $uploadedfile = $1; } else { error( $grab_file, "Invalid file name; files must star +t with a letter or number." ); } # This will create the new file in the new location until ( sysopen OUTFILE, UPLOAD_DIR . $uploadedfile, O_RDW +R|O_CREAT|O_EXCL, 0777 ) { $uploadedfile =~ s/(\d*)(\.\w+)$/($1||0) + 1 . $2/e; $1 >= MAX_OPEN_TRIES and error( $grab_file, "Unable to + save your file. File 1" ); } # The file needs to be set to binmode in order to save it +on a Win32 system binmode OUTFILE; binmode $file_handle; # This will write the info into the new file while ( read($file_handle,$buffer,BUFFER_SIZE) ) { print OUTFILE $buffer; } close OUTFILE; my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$file_size,$ati +me,$mtime,$ctime,$blksize,$blocks) = stat($file); # This will store the file and size in the database push @statement,"INSERT INTO documents (record_id, documen +t, size) VALUES ('$record_id', '$uploadedfile', '$file_size')"; } } }
Thanks in advance for your help. -Kiko

Replies are listed 'Best First'.
Re: I'm getting an error using error()
by tachyon (Chancellor) on Aug 07, 2001 at 20:37 UTC

    This looks like the script out of the ORA CGI book. Your problem is that the error() sub is missing. You need to define this sub. This is the sub out of the book which looks like it should fit.

    sub error { my( $q, $reason ) = @_; print $q->header( "text/html" ), $q->start_html( "Error" ), $q->h1( "Error" ), $q->p( "Your upload was not procesed because the following e +rror ", "occured: " ), $q->p( $q->i( $reason ) ), $q->end_html; exit; }

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      That did it. Thanks for your help.
Re: I'm getting an error using error()
by rchiav (Deacon) on Aug 07, 2001 at 20:34 UTC
    Where does the sub "error" exist? is this from a module? is it a sub someplace else within the script? As far as I know, perl doesn't have a built in function named "error"

    Rich