Here ya go guys/gals:

HTML:

<form action="/test/test.pl" method="post" ENCTYPE="multipart/form-dat +a"> <INPUT TYPE="file" NAME="photo"> <INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="Submit Form"> </form>

CGI:

use strict; use CGI::Carp qw(fatalsToBrowser); use CGI qw( :standard); use File::Slurp qw( read_file ); use DBI; use Crypt::Lite; use File::Basename; ############################################### # CGI IN my $query = CGI->new; my $submit = $query->param('SUBMIT'); my $user_id= $query->param('USER_ID'); my $filename = $query->param("photo"); my $safe_filename_characters = "a-zA-Z0-9_.-"; my $upload_dir = "\images-user"; $CGI::POST_MAX = 1024 * 5000; ############################################### if ($user_id eq '') { my $cookie = CGI->new; $user_id = $cookie->cookie('TEC_USER_ID'); my $crypt = Crypt::Lite->new( debug => 0, encoding => 'hex +8' ); my $decrypted = $crypt->decrypt($user_id, $ip_address) +; $user_id = $decrypted; } #################################################### ##################### Main Page #################### #################################################### # Start Main Page if ($submit eq '') { #code } elsif ($submit eq 'Submit Form') { if ( !$filename ) { print $query->header ( ); print "There was a problem uploading your photo (try a smaller fil +e)."; exit; } my ( $name, $path, $extension ) = fileparse ( $filename, '..*' ); $filename = $name . $extension; $filename =~ tr/ /_/; $filename =~ s/[^$safe_filename_characters]//g; if ( $filename =~ /^([$safe_filename_characters]+)$/ ) { $filename = $1; } else { die "Filename contains invalid characters"; } my $upload_filehandle = $query->upload("photo"); open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!"; binmode UPLOADFILE; while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE; }

Hope that helps!


In reply to Re^4: File Upload On Windows 8 and Perl by skosterow
in thread File Upload On Windows 8 and Perl by skosterow

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.