This is the code ive just managed to get working - it allows a client to upload a file to the . directory on the server
In order to get this to work, I had to chmod the current working directory to 777. This isnt wise is it?. Is there a way of temporarily changing the permissions of a directory for the purpose of allowing a file to upload?, or something of that nature. In otherwords what improvements can I make to the code below in order to make it more secure.
#!/usr/local/bin/perl use strict; use CGI; my $query = new CGI; my $dir = $query->param('dir'); my $file = $query->param('file'); $file =~m/^.*(\\|\/)(.*)/; my $name = $2; my $error; #open(LOCAL,">$dir/$name") or $error = $!; open(UP_FILE,">$name") or $error = $!; while(<$file>) { print UP_FILE $_; } print $query->header(); print $query->start_html("File Upload"); # DEBUG TO SCREEN print $query->br,$error,$query->br,$file,$query->br,$name; print $query->end_html;

In reply to File upload and directory permissions by Baz

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.