http://qs1969.pair.com?node_id=525580

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

Can someone tell me a good method of uploading a csv file via CGI so that I could read its contents with DBI? All I would like to do is get file stored on the server so it can be opened by perl code and read.

Here is a code snippet I created to test interaction in the CGI for getting information on the name and type of file:
use CGI qw(:standard); print "Content-type: text/html\n\n"; &main; sub main() { my $query = new CGI; my $indexTemp = HTML::Template->new(filename => 'index.tmpl'); my $fileName = $query->param('filepath'); my $type = $query->uploadInfo($fileName)->{'Content-Type'}; print $query->param('eventname')."<br />\n"; print $query->param('date')."<br />\n"; print $query->param('starttime')."<br />\n"; print $query->param('endtime')."<br />\n"; print $query->param('location')."<br />\n"; print $fileName."<br />\n"; print $type."<br />\n"; } }
Thank you in advance for your help.
---------------------
Keep your concentration here and now where it belongs - Qui-Gon Jinn

Replies are listed 'Best First'.
Re: Uploading a CSV file using the input file html form object
by lima1 (Curate) on Jan 25, 2006 at 22:27 UTC
    use the upload() function (perldoc CGI).

    in your upload_results page, you must check what you got (valid file handle? cgi_error? correct format?). Then simply store the data (open my $FH, '>', $secure_destination), or store it directly in db.

      Thank you, this helped!
      ---------------------
      Keep your concentration here and now where it belongs - Qui-Gon Jinn