Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: File Upload + recording

by btrott (Parson)
on Mar 05, 2000 at 11:22 UTC ( [id://4896]=note: print w/replies, xml ) Need Help??


in reply to File Upload + recording "metadata"

Yeah, sending a file from the same form as some "text values" works fine. Have you investigated CGI.pm? You should.

You can use it to create the form for uploading the file (the form "enctype" has to be "multipart/form-data"). And then you can use it to proces the file upload, the title, and the description.

use CGI; my $query = new CGI; my $fh = $query->upload('uploaded_file'); open OUTPUT, ">/foo/save" or die "Can't open: $!"; while (<$fh>) { print OUTPUT; } close OUTPUT or die "Can't close: $!"; my $title = $query->param('title'); my $description = $query->param('description'); # now write them to a file...
CGI.pm also lets you access some metadata about the file, using the "uploadInfo" method. For more info, take a look at the CGI.pm docs.

Replies are listed 'Best First'.
RE: Re: File Upload + recording
by brett (Initiate) on Jun 15, 2000 at 06:25 UTC
    Should perhaps be:
    < my $fh = $query->upload('upload_file'); > my $fh = $query->param('uploaded_file'); # file input control is named "uploaded_file" and < open OUTPUT, "/foo/save" or die "Can't open: $!"; > open OUTPUT, "> /foo/save" or die "Can't open: $!";
    One problem I've found is that when uploading files larger than around ~60-70k, I get a problem in trying to instantiate CGI.pm. (Apache flips me the bird and takes me to an error screen). Is this a known problem? Has anyone else struck this?
      You're right about the open on the OUPUT filehandle. I think we're both right on the first thing (param vs. upload), though. :) As the CGI.pm docs say this:
      To be safe, use the upload() function (new in version 2.47). When called with the name of an upload field, upload() returns a filehandle, or undef if the parameter is not a valid filehandle. $fh = $query->upload('uploaded_file');
      Calling param on an uploaded file field gives you a thing that's both a string and a filehandle. Using upload just makes sure you get a filehandle, as it's less of a security risk.

      As to your question re: big uploads: do you get any out of memory errors? 60-70k doesn't seem like *that* big a value. Could it be a POST limitation?

        Yes, my apologies. It turns out I was using an old version of CGI.pm Upgraded and unearthed the upload() function.
        Just trolled the apache error logs and can see an error message being generated from mod_perl:
        [client xxx.xx.xxx.xxx] Request content-length of 84482 is larger than the configured limit of 75000
        Which probably explains my problem with file upload size :)
        Thanks a lot for your help.

        *a bit later* Turns out this:

        LimitRequestBody 75000
        was in my httpd.conf file! *slaps forehead*

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://4896]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-25 08:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found