As posted your code is almost unreadable. (When you post code to PM, put it between <code></code> tags. Better yet, become familiar with the contents of the PM site FAQ, especially Writeup Formatting Tips.) Rather than try reading through it, here's a simple file upload script:

#!/usr/bin/perl -T -- use strict; use warnings; use CGI qw(:standard); print header, start_html('Upload example'); print_form() unless param; print_results() if param; print end_html; sub print_form { print h2('What file do you have for me?'), start_multipart_form(), filefield(-name => 'upload', -size=>60), submit(-label => 'Do it!'), end_form; } sub print_results { my $output_file = '../whatever'; my $file = upload('upload'); print h2('Bummer!...') and return unless $file and open my $out, ">$output_file"; { my $data; print $out $data while read $file, $data, 1024; } close $out or print h2('Not all is well...') and return; print h1('Success!'); }
Make sure that the script has permission to write to $output_file.

Update: Fixed s/param/upload/ in print_results; the original works but the revision uses the "recommended idiom" (see perldoc CGI for a discussion on this).

the lowliest monk


In reply to Re: Upload a file from home dir by tlm
in thread Upload a file from home dir by MonkPaul

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.