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

Dear Monks, I have a cgi script which uses forms to pass information into a sql table. The script reloads its self dependent on the number of entries defined by the user. This works perfectly fine. However, I am having problems uploading the file defined by the user - using html form types. The name of the file is created but nothing written to it. The following code takes the information from the form which is used to update sql. I have omitted the the post methods to process info .
$previouspage =$ENV{'HTTP_REFERER'}; ### i know this is not the best solution if ($previouspage =~ m/int/) { ##define scalars. $query = new CGI; $filename = $query->param("profile_data"); #read infilename of data open(OUTPUT, ">$filename"); binmode $filename; binmode OUTPUT; ($bytesread,$buffer,$total); while ($bytesread = read($filename,$buffer,1024) ) { $total += $bytesread; if ($bytesread > 10000000) { close(OUTPUT); unlink "$filename"; } print OUTPUT $buffer; } + close(OUTPUT); }
Thanks

Replies are listed 'Best First'.
Re: File upload probelem
by jasonk (Parson) on Apr 05, 2006 at 12:38 UTC

    Well, you've omitted the form (and left us guessing at exactly what is going on, since you don't mention _how_ it isn't working. But for a wild guess I'd say you didn't set the 'enctype' of the form correctly, if you are using CGI.pm to build your form make sure you are using start_multipart_form() and not start_form(), if you are writing your own form tags, make sure your form tag includes enctype="multipart/form-data" and consider reading the file upload portions of the CGI.pm documentation...


    We're not surrounded, we're in a target-rich environment!
      thanks for the suggestion, it appears to be a form problem.
Re: File upload probelem
by Anonymous Monk on Apr 05, 2006 at 12:28 UTC
    i have tested the upload code on a simple web form and it works fine. So its not a read/write permission problem.