Hey,

I'm still having some problems that I can't seem to figure out. I'm concerned that I'm not even on the right track and I'm using CGI.pm totally wrong? I'm on a Windows machine.

This script uses Data::FormValidator along with CGI::Application::ValidateRM to validate the form input. The beginning part of the script is mostly the form_display and form_process to dispaly and validate the form, after is the upload portion where I've been stuck on since early mourning. I recently posted a thread on setting the size restriction for uploaded files. I seem to have that working in a way.

Heres my situation. Lets say I set $CGI::POST_MAX = 1536000 to $CGI::POST_MAX = 20. When trying to submit the form, it'll return a blank template (upload.tmpl). Somehow I'm getting a sense that the POST_MAX is working considering, when I change it back to 153600 and try to submit the form, the whole process works--Including uploading the file.

My main problem is retrieving the error message if a file being uploaded surpasses my limit, which in my case, 1.7mb. I used comments in the upload process portion of the script to describe what Is wrong and where I'm having trouble on,so I don't think you really need to focus much on this script but the results and upload portion.

Here's my following code:

package BusinessFormValidation; use base CGI::Application; use CGI::Application::ValidateRM; use Data::FormValidator; use CGI; $CGI::POST_MAX = 1536000; #$CGI::POST_MAX = 1536000; #~1.7MB use strict; print "Content-type: text/html\n\n "; sub setup { my $self = shift; $self->start_mode('form_display'); $self->run_modes([qw/ form_display form_process # data_process # upload_process /]); } sub form_display { my $self = shift; my $errs = shift; my $t = $self->load_tmpl('upload.tmpl',die_on_bad_params=>0); $t->param($errs) if ref $errs; return $t->output; } sub form_process { my $self = shift; my ($results,$err_page) = $self->check_rm('form_display', { required => [qw/ industry firstname lastname company address1 city us_states country zip_code ci_month ci_year p1 p2 p3 /], optional => [qw/ title province address2 f1 f2 f3 website zip_codex /], # dependencies => { # name1 => [ '2_name'], # }, constraints => { zip_code => 'zip', ci_email => 'email', }, # trim leading and trailing whitespace from all the val +id fields. filters => ['trim'], field_filters => { cc_no => "digit", zip_code => "digit", zip_codex => "digit", p1 => "digit", p2 => "digit", p3 => "digit", f1 => "digit", f2 => "digit", f3 => "digit", }, msgs=>{ any_errors => 'err__', prefix=>'err_', format => ' <b><font color="white" face="verdana" size +="1">*</font><font face="verdana" size="1">%s</font></b>', }, }); return $err_page if $err_page; #basic form elements are valid , upload validation/process: #foreach my $f ( $results->valid() ) { # print $f, " = ", $results->valid( $f ), "\n"; # } #prints out the form results. my $upload_dir = "C:/web site/uploads"; my $business_plan_file = $results->valid('file_name'); #upload f +iled name is file_name $business_plan_file =~ s/.*[\/\\](.*)/$1/; #retrieve filename +w/out full path my $upload_filehandle = $results->valid('file_name'); ## #my $content_type = $upload_filehandle->uploadInfo($business_plan_file +)->{'Content-Type'}; #print "hi"; if I uncomment this and the line above, the script will + somehow seem to die and will not print "hi" ## my $error = $upload_filehandle->error(); #this is where my main problem is being caused. Somehow its not retri +eving the error messages if the POST surpasses 1.7 mb. if ($error) { print "$error"; die; } #elsif { #my $content_type = $cgi->uploadInfo($business_plan_file)->{'Content-T +ype'}; #this will be placed if it passes the POST requirement length, then wi +ll check for specific MIME types allowed #} #this is the simple upload script I'm using, does this involve anythin +g whatsoever with the CGI.pm module? It seems like this code could +just be ran w/out "use CGI.pm" else { open UPLOADFILE, ">$upload_dir/$business_plan_file" || die; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE; } } 1;


I'm just not sure about this problem. It seems like I'm on the right track with doing this but probably missing something that I'm not aware of. I checked the docs etc and still no luck when trying to play with it. Am I even on the right track with what I want to do? Which is validate a form, validate a upload, upload the acutal file, and then the rest is to insert the data into a mysql table-which I'm sure I won't have trouble with once I get the upload process done.

Thanks,
Anthony

In reply to My Upload script, Am I even on the right track? by perleager

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.