koleti has asked for the wisdom of the Perl Monks concerning the following question:

hello monks, I am working to build a webtool
if the user wants to use that tool he has to upload a file in to my server
but i don't know how make the user upload a file any ideas!
  • Comment on how can i upload a file to my webserver

Replies are listed 'Best First'.
Re: how can i upload a file to my webserver
by Snarius (Sexton) on Dec 04, 2007 at 00:13 UTC
    There's a CGI field for this. http://search.cpan.org/dist/CGI.pm/CGI.pm#CREATING_A_FILE_UPLOAD_FIELD
Re: how can i upload a file to my webserver
by Cody Pendant (Prior) on Dec 04, 2007 at 02:03 UTC
    See this from the Q&A section for an example.


    Nobody says perl looks like line-noise any more
    kids today don't know what line-noise IS ...
Re: how can i upload a file to my webserver
by agianni (Hermit) on Dec 04, 2007 at 02:15 UTC
    CGI::Upload is a subclass of CGI, which makes file uploads even simpler than the method documented in the CGI module POD as suggested by Snarius.
    perl -e 'split//,q{john hurl, pest caretaker}and(map{print @_[$_]}(joi +n(q{},map{sprintf(qq{%010u},$_)}(2**2*307*4993,5*101*641*5261,7*59*79 +*36997,13*17*71*45131,3**2*67*89*167*181))=~/\d{2}/g));'
      Can anyone explain the reference to
      mime_magic('/path/to/mime.types')
      in the CGI::Upload module?

      It says to refer to File::MMagic for details, but I don't see any.



      Nobody says perl looks like line-noise any more
      kids today don't know what line-noise IS ...
        What kind of details do you want?
        mime_magic('/path/to/mime.types') This method sets and/or returns the external magic mime types file + to be used for the identification of files via the mime_type method. + By default, MIME identification is based upon internal mime types de +fined within the File::MMagic module. See File::MMagic for further details. mime_type('field') This method returns the MIME type of the file uploaded through the + form input field named 'field' as determined by file magic numbers. +This is the best means by which to validate the nature of the uploade +d file. See File::MMagic for further details. File::MMagic - Guess file type This module is to guess file type from its contents like file(1) command.
Re: how can i upload a file to my webserver
by RaduH (Scribe) on Dec 04, 2007 at 00:12 UTC
    you cold use a system call to scp to transfer your file after having had the user input (or browse for) the file name, something like :
    system("scp $sourceFileName $storageAccount\@$storageServer:".'~'."/s +torage");
    This assumes the name of the file you want to upload is in $sourceFileName and the rest is the destination: the account and server followed by colon and the path to where the file should be store. In that example the path begins with the home of $storageAccount and goes into the storage directory. You can of course modify that to be any path, starting even with /. Check out the scp man page, you'll get a good description.

    This offer secure file transfer but you may need to provide a password for your upload to work. To automate that read this

    Of course, this use scenario may not fit your needs (you may not want to / be able to do that key exchange) but it is one variant I could suggest based on what info you provided.

    Here's additional pointers if the above doesn't match your needs (again, I think your problem is a little under-specified): link1 and link2 and link3 Hope this helps.

Re: how can i upload a file to my webserver
by zentara (Cardinal) on Dec 04, 2007 at 13:26 UTC
    Here is a little Tk script that will upload a file to a specific cgi program you run on your server. It has a progressbar and text output for stderr messages. You can modify it to use basic auth if desired, or have specific passwords for each user. (just add a form field to the upload)

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum