Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

file upload form

by amt (Monk)
on Dec 28, 2004 at 20:12 UTC ( #417834=perlquestion: print w/replies, xml ) Need Help??
amt has asked for the wisdom of the Perl Monks concerning the following question:


I have been asked to create a form to upload CSV of site surveys, and then emailing that file to my engineering department.

The HTML half of the script is as follows:
<form name=csvsurvey method=post action='/' enctype='multipart/form-da +ta'> <input type=hidden name=cmd value=main> <input type=hidden name=module value=Customer> <input type=hidden name=sub_cmd value=site_csv> <input type=hidden name=sub_module value='Site Survey'> <tr><td class=oatable>CSV File to Upload</td><td class=oatab +le><input type=file name=upfile></td></tr> <tr><td class=oatable>Notes(80 char max)</td><td class=oatabl +e><input type=text name=upnote maxlength=80></td></tr> <tr><td class=oatable colspan=2 align=center><input type=subm +it value='Upload File'></td></tr></form>
The function that handles the incoming file is as follows:
sub site_csv() { # Get CGI Variables CGI::ReadParse(*form); my $csv = $form{upfile}; $csv =~ s/\n/<br>/gi; my $note= $form{upnote}; $tokens{MAIN} = "Included note: $note<br>"; $tokens{MAIN} .="<br>$csv<br>"; return $tokens{MAIN}; }
As you can tell I haven't even gotten to the point where I need to attach the file to an email. I want to be able make sure that I can recieve the information. The problem is that when I send my file, test.csv, printing out $form{upfile} prints the file name of the file that was uploaded, rather than the data.



Replies are listed 'Best First'.
Re: file upload form
by steves (Curate) on Dec 28, 2004 at 20:36 UTC

    If you read the CGI docs carefully, you'll see that uploaded files are presented to the CGI application as both a name and a filehandle. Those docs illustrate usage better than I can.

      Thank you. It's near the end of the day, so I was trying to avoid the whole RTFM ;). I'll read the docs.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://417834]
Approved by Old_Gray_Bear
LanX likes Swedish clogs

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2017-12-15 16:54 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (439 votes). Check out past polls.