Wednesday, April 6, 2011

What is the Perl equivalent for PHP's $_FILES for file uploads?

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'];
        }
?>
From stackoverflow
  • 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');
    
    Dave : 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?
    daotoad : 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.
    Dave : Yeah, using my @files = $q->upload();

0 comments:

Post a Comment