John Pretti <[EMAIL PROTECTED]> wrote: : Can someone point me in the right direction of converting : the following script to use an html template?
You don't need html templates for this. Your pages are static. They don't have any information added to them by the cgi program. You can remove the html code from the script though. : #!/usr/bin/perl -w : # perlUpload.cgi by John Pretti : # Comments/Questions john[at]web-connected.com : # Last modified 05/03/04 : : # Load needed Perl modules : use strict; : use diagnostics; : use CGI; # Make HTML easy to deal with : use CGI::Carp 'fatalsToBrowser'; # Report errors to browser : $CGI::POST_MAX=1024 * 100; # max 100K posts : : # Allowed file types : my @good_extensions = ('doc', 'DOC', 'Doc', 'rtf', 'RTF', 'Rtf', : 'pdf', 'PDF', 'Pdf'); A hash would be more convenient. # Allowed file types my %is_valid_extension = ( doc => 1, rtf => 1, pdf => 1, ); Then replace all this stuff: my $ingood_extensions = 0; foreach ( @good_extensions ) { if ( $_ eq $extension ) { $ingood_extensions = 1; } } if ($ingood_extensions == 1) { With: if ( %is_valid_extension( $extension ) ) { : # Create new CGI object : my $q = new CGI; : : if ( $q->param() ) { : : # Read filehandle from param and set to binary mode : my $filehandle = $q->param('file'); : binmode($filehandle); : : # Strip off Windoze crap compliments of JHARRISS : $_=$filehandle; s/.*\\//; : my $filename=$_; : : # Check to see if filetype is allowed compliments of JHARRISS : $_=$filename; s/.*\.//; : my $extension=$_; : my $ingood_extensions=0; : foreach (@good_extensions) { : if ($_ eq $extension) { : $ingood_extensions=1; : } : } : if ($ingood_extensions == 1) { : : : # Open file for output : open(OUT,">/www/web/htdocs/merlin/upload/$filename") ::: die $!; : binmode(OUT); : :: 92 : $q->start_multipart_form, : $q->filefield('file'), : $q->br, : $q->submit('Upload'), : $q->end_form, : $q->end_html; : exit (1); : } This section doesn't make sense. I doubt it does what you want. It needs to be re-written. There's no print in there. Why open a file and not do anything with it? And what is the :92 label for? : } else { Here are the first complete pages. Write the page as a separate html file and redirect() to it here. if ($q->cgi_error()) { print $q->redirect( 'failure_form.html' ); } else { print $q->redirect( 'file_upload.html') } : if ($q->cgi_error()) { : print $q->header, : $q->start_html('Merlin : Control Center'), : $q->p("File upload has : failed. Files must be : under 4MB in size. Please try again"), : $q->start_multipart_form, : $q->filefield('file'), : $q->br, : $q->submit('Upload'), : $q->end_form, : $q->end_html; : } else { : print $q->header, : $q->start_html('Merlin : Control Center'), : : $q->img({-src=>'/merlin/images/usda.gif'}), : $q->br, : $q->start_multipart_form, : $q->filefield('file'), : $q->br, : $q->submit('Upload'), : $q->end_form, : $q->end_html; : } : : } : : While the above script, works perfectly, I would like to : make it look a lot more attractive and I am having some : troubles understanding how to get my html code to play : nicely with CGI.pm. Thanks in advance. Are you sure the script works right. Let's take a look. Here's the logic of the script. my $q = new CGI; if ( $q->param() ) { print 'we are in the file upload section'; } else { if ($q->cgi_error()) { print 'there is an error'; } else { print 'printing form'; } } Now let's test that logic. First we'll test for the error. my $q = new CGI; $q->param( cgi_error => 'Error' ); if ( $q->param() ) { . . . Result: we are in the file upload section Uh Oh! That's not working perfectly. Test your scripts better! HTH, Charles K. Clarkson -- Mobile Homes Specialist 254 968-8328 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>