views:

420

answers:

1

What is the Perl equivalent of PHP's $_FILES? I've got some software that sends log files to a web server and I need to retrieve them using Perl instead of PHP. I'm using CGI.pm.

Here's the code in PHP:

<?
    foreach ($_FILES as $key=>$value)
        {
         $uploaded_file = $_FILES[$key]['tmp_name'];
        }
?>
+12  A: 

It's in the pod:

my $q = CGI->new();

# get filehandle like objects from the query. 
my @uploaded_files = $q->upload();

# get file by name
my $fh = $q->upload('uploaded_file');
daotoad
I actually couldn't get $q->upload to work - I had to explicitly call the name using $q->upload('uploaded_file'). Not sure why. Have you been able to loop through uploaded files without knowing the name?
Dave
Are you assigning the results in a list context, for example to an array? my @files = $q->upload(); or (my $file) = $q->upload(); It's been a long time since I did anything with CGI.pm, and I don't recall if I used the list context version of upload.
daotoad
Yeah, using my @files = $q->upload();
Dave