i do it like this:
use Fcntl qw( :DEFAULT :flock ); use CGI; use constant BUFFER_SIZE => 16_384; use constant MAX_FILE_SIZE => 1_048_576; # Limit each upload to + 1 MB use constant MAX_DIR_SIZE => 100 * 1_048_576; # Limit total uploads +to 100 MB use constant MAX_OPEN_TRIES => 100; no strict; $CGI::DISABLE_UPLOADS = 0; $CGI::POST_MAX = MAX_FILE_SIZE; our $page = new CGI; print $page->header(); print $page->start_html( -title => $TITLE, -style => { 'src'=> $style }, ); $page->cgi_error and error( $page, "Error transferring file: " . $page +->cgi_error ); my $filename = $page->param( "file" ) || error( $page, "No filename e +ntered." ); my $fh = $page->upload('file'); # upload takes the name of "inp +ut file upload"-field if (!$fh && $page->cgi_error) { print $page->header(-status=>$page->cgi_error); exit 0; } my $buffer; if ( dir_size( $UPLOAD_DIR ) + $ENV{CONTENT_LENGTH} > MAX_DIR_SIZE ) { error( $page, "Upload directory is full." ); } # Allow letters, digits, periods, underscores, dashes # Convert anything else to an underscore $filename =~ s/[^\w.-]/_/g; if ( $filename =~ /^(\w[\w.-]*)/ ) { $filename = $1; } else { error( $page, "Invalid file name; files must start with a lett +er or number." ); } # Open output file, making sure the name is unique until ( sysopen(OUTPUT, $UPLOAD_DIR . $filename, O_WRONLY | O_EXCL | O +_CREAT) ) { $filename =~ s/(\d*)(\.*\w+)$/($1||0) + 1 . $2/e; error( $page, "Unable to save your file." ) if $1 >= MAX_OPEN_ +TRIES ; } # This is necessary for non-Unix systems; does nothing on Unix binmode $fh; binmode OUTPUT; while ( read( $fh, $buffer, BUFFER_SIZE ) ) { print OUTPUT $buffer; } close OUTPUT; my $sql_insert = "INSERT INTO bonsai_pics (name,bonsai_id,filename,tim +estamp) VALUES (?,?,?,?)"; $dbh->do($sql_insert,undef, $page->param('name'), $page->param('bo +nsai_id'), $UPLOAD_DIR . $filename, $date) || error $page,"Could not +insert $sql_insert :\n"; print "<b>Added $filename</b><br />";
if I remember it correctly: it's based on an example i once found...
hope this helps (don't forget the binmode thingie ;-) )
--
to ask a question is a moment of shame
to remain ignorant is a lifelong shame

In reply to Re^3: uploading jpg files to server by insaniac
in thread uploading jpg files to server by Anonymous Monk

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.