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

I need to create a Browse button on a web page to enable the user to select a file from her harddisk and then have a perl program read and process that file.

The html code to create a 'Browse' button is as follows:

<INPUT TYPE="FILE" NAME="textfile" SIZE="20">

What sort of code is needed in the perl cgi to interact with the file once it is selected? I am quite familiar with 'use CGI' but have absolutely no idea about the kind of code needed to access a file (probably a text file) from the user's harddisk.

Please advise.

kiat

  • Comment on access file in harddisk through a web page...

Replies are listed 'Best First'.
Re: access file in harddisk through a web page...
by Asim (Hermit) on Nov 09, 2001 at 19:33 UTC

    You have to have the user actually upload the file to your web server before you can do anything at all with it. Read CGI.pm's docs on File Upload for more on that.

    If you really, really need to access the user's files on their local Hard Drive...you'll have to code something in Java, and prepare to ask the user for access. But I'd highly recommend against it.

    ----Asim, known to some as Woodrow.

Re: access file in harddisk through a web page...
by Fastolfe (Vicar) on Nov 09, 2001 at 21:19 UTC

    As the previous poster said, the user is submitting this file as an HTML form field. Your script, when it uses CGI.pm and parses the form submission from the user, will end up having access to the file data sort of like the other form fields.

    The documentation for CGI.pm has a lot of documentation and code examples on how to do this. Give it another read.