Disclaimer: very unsafe script for any kind of use. Will overwrite any file that you give a path for. Be careful if you test it. Don't be uploading to a path of '/etc/passwd' if you're root :)

#!/usr/bin/perl -w use strict; use CGI ':standard'; # Print out the html page sub print_html { my ($title, $msg) = @_; print header, start_html($title), start_multipart_form, p($msg), table( Tr( th( 'Upload Path:' ), td( textfield({ name => 'upload_path', default => './upload.txt' }) ) ), Tr( th( 'File to Upload:' ), td( filefield({ name => 'upload_field' }) ) ), Tr( { colspan => 2 }, th( submit({ value => 'Upload File' }) + ) ) ), end_form, end_html; exit; } print_html( 'Upload File', 'Please select the file you wish to upload:' ) unless defined param('upload_field'); my $fh = upload('upload_field'); open UPLOAD, '>' . param('upload_path'); binmode UPLOAD; print UPLOAD while <$fh>; close UPLOAD; print_html( 'Upload Complete', "File $fh has been uploaded.<br /> You can now upload another file if you wish:" );


In reply to Re: How to write an uploaded file in a specific dir by Coruscate
in thread How to write an uploaded file in a specific dir by le_visionaire

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.