What does your file field look like in your form? Are you sure that your form has the appropriate type? That is, if you're planning on uploading files then you have to tell your browser to expect to upload a file:
<form action="upload.cgi" method="POST" enctype="multipart/form-data">
assuming of course that your script is called upload.cgi.

Likewise your file field should look something like this:

<input type="file" name="filename">
If you don't specify your form type with enctype="multipart/form-data" then you'll get your filename in your parameters but no file.

On a separate issue, you're running a big risk by not ensuring that the filename you're creating is unique. If you're uploading resumes for example you'll find that many people call their files "resume.doc" and they're all over-write each other. The same can be true of photos and other random files.

The link I gave before pointed to code that should have helped there, but I'll write it out for you here too.

sub uploadfile { use strict; # a good thing to do use File::Basename; my ($q, %user) = @_; # look through all five upload options and # save any uploaded files for (my $i=1; $i<=5; $i++) { my $file = $q->upload("file$i"); next unless $file; # find the filename and it's extension my ($filename, $type) = split '\.', basename($fh); # untaint the filename and extension $filename =~ s/[^A-Za-z0-9_-]//g; $type =~ s/[^A-Za-z0-9_-]//g; my $directory = $user{'site_id'}; # make a unique filename my $i = 0; while(-e "$directory/$filename$i.$type") { $i++; } # this won't write over anything else. my $newfilename = "$directory/$filename$i.$type"; # Write contents of uploaded file to $director +y open(FILE, "> $newfilename") or die "$!\n"; { local $/=""; my $uploaded = <$filename>; print FILE $uploaded; } close FILE or die "$!"; } }
Using upload() is preferrable to using param() because it returns a filehandle which is magical and can act as a string. This means that you can use strict throughout without it complaining about symbolic references.

Hope this helps.

jarich


In reply to Re: Re: perl trouble by jarich
in thread Problem with CGI File Upload (was: perl trouble) by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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, details, 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, summary, 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.