Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

how can i upload a file using a web-browser and the chmod() the file ?

by Digsy (Initiate)
on Sep 27, 2000 at 18:27 UTC ( #34202=categorized question: print w/replies, xml ) Need Help??
Contributed by Digsy on Sep 27, 2000 at 18:27 UTC
Q&A  > HTTP and FTP clients


I am trying to write a script that will upload a script from a PC via a web-browser. (The PC cant have FTP or perl) The script would be put onto a secure FTP server and then chmod'ed so that the script could be executed.

Answer: how can i upload a file using a web-browser and the chmod() the file ?
contributed by merlyn

File uploading is fairly painless with From the manpage:

CREATING A FILE UPLOAD FIELD print $query->filefield(-name=>'uploaded_file', -default=>'starting value', -size=>50, -maxlength=>80); -or- print $query->filefield('uploaded_file','starting value',50 +,80); [...] When the form is processed, you can retrieve the entered filename by calling param(): $filename = $query->param('uploaded_file'); [...]
You can then copy the file to the appropriate place (perhaps using the File::Copy core module), and then use the chmod operator to make it executable.

An important security concern is to make sure your script is not available to the general populus, because you've effectively given an open prompt to whomever wants it.

Answer: how can i upload a file using a web-browser and the chmod() the file ?
contributed by AgentM

Minimally, you will want to turn on taint checking with -T. If you are uploading a picture, you'll want to check its "pictureness" with Image::Magick or some similar Module. In any case, you should set a maximum size for the file in the CGI Module using $CGI::POST_MAX and optionally scan the file to make sure that its corresponds with some given format. In the name of security, you should definitely take these extra steps to ensure the sanity of your filesystem.

Please (register and) log in if you wish to add an answer

  • 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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [GrandFather]: It's a good day end here Corion. The start was somewhat less than average!
    [Corion]: GrandFather: All's well that ends well? ;)
    [GrandFather]: I'm fighting with a third party device our software is to support. The documentation for the device's SDK is quite a lot less than average and most of today was spent ...
    [GrandFather]: discovering that one of the sensors for the device lies about the gain range it is using!
    [GrandFather]: However, by the end of the day I had discovered its deceptions and now have it working correctly, so yes, all's well that ends well. :-D
    [Corion]: GrandFather: Ah, (hardware) APIs - I have a similar situation with Chrome and its API... It is fairly underdocumented and I guess I have to hunt...
    [Corion]: ... down supposedly working code to find out what I'm supposed to do
    [GrandFather]: I haven't any "working code" to inspect! I have to find ways to generate reference signals then check the numbers I get at the far end match.

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (5)
    As of 2017-08-24 07:08 GMT
    Find Nodes?
      Voting Booth?
      Who is your favorite scientist and why?

      Results (365 votes). Check out past polls.