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

helloo all!

I'm trying to get my upload code working. I'm not sure whats wrong with it and I can't debut at all!!!!!! This script is being hosted on a shared server--heres the deal. When I delete the following block of coding, the script runs fine (adds to database, prints successful html msg, etc). BUT, when I add the following code, all it does is SHOW BLANK on the browser, leaving me clueless on what the error/problem is? Since this is a shared server, I created a directory thats chmod'ed to 777.
my $fhx = $INPUT->upload('file_name'); my ($Bytes, $Buffer); open OUTPUT, '>'."/home/gambler_add/adpics/testing.gif" or die "Ca +n't open: $!"; while ($Bytes = read($fhx, $Buffer,1024)) { print OUTPUT $Buffer; } close OUTPUT or die "Can't close: $!"; #After this coding, I have more coding that adds form values into a db +.
I am using strict and warnings and taint. Also using CGI and the object name is $INPUT.

I do have the proper html form coding---(enctype="multipart/form-data")

Its a Linux machine so pretty sure its not because I left out binmode.

I can't seem to figure out whats wrong? I do have CGI upload enabled and the max post is well beyond the size of file I'm trying to upload.

Thanks!

Replies are listed 'Best First'.
Re: uploading a image file
by svenXY (Deacon) on Oct 20, 2005 at 10:02 UTC
    Hi,

    first of all, did you have a look at the Apache error log as that is where perl/cgi writes it's errors to? Then you can use CGI::Carp qw(fatalsToBrowser);. CGI::Carp prints your error messages to the browser so that you do not have to search for them in the error log.

    That should help you debugging.

    Regards,
    svenXY
Re: uploading a image file
by archen (Pilgrim) on Oct 20, 2005 at 15:53 UTC

    Okay, this is going to sound stupid, but if no one else comes up with a solution I would suggest that you mess with the code using alternative methods to achieve the same results. Personally I use CGI::Simple, but I've had even more problems with that module for some unknown reason than I've had with strait CGI;

    For some reason on occasion I have severe problems with the "upload" routine of CGI. Instead I sometimes use the older method.
    my $fh = $cgi->param('file'); open FILE, ">whatever"; print FILE while (<$fh>);
    Reading the file in blocks as you have it is a better solution, but this is pretty tried and true for getting it to work initally. CGI::Simple also provides:
    my $st = $cgi->upload( $cgi->param('file'), ">whatever");
Re: uploading a image file
by Anonymous Monk on Oct 20, 2005 at 07:04 UTC
    helloo

    Okay I sorta changed the coding I posted above justa bit. replace open OUTPUT, '>'."/home/gambler_add/adpics/testing.gif" With open OUTPUT, '>'."/home/gambler_add/adpics/$my_filename" When just having "testing.gif", the upload code actually works....but my goal is to create a random name for the file being uploaded , and thus having it be stored as $my_filename.

    thanks!