Reputation: 17477
I have used CGI::Simple
in the past, for a general purpose upload processor. I apparently used an internal method called upload_fieldnames
, which returns an array of field names that are uploads.
I am trying to adapt this code to use CGI.pm, because it is more commonly available for CentOS 7. How would I get a list of only file upload fields? All of the examples I've found use known field names, which I don't know in advance. Other fields might be submitted with the form, and I only need to act on the ones that provide a file upload.
Upvotes: 2
Views: 102
Reputation: 69314
CGI.pm doesn't have an equivalent of the upload_fieldnames()
method, but you can synthesise something by using a combination of the param()
and upload()
methods. param()
will give you a list of all of the parameter names and you can use upload()
to check whether or not each one is a file upload.
my @upload_fieldnames;
foreach (param()) {
push @upload_fieldnames, $_ if upload($_);
}
Or, as a one-liner:
my @upload_fields = grep { upload($_) } param();
Update: I just wanted to add a comment on this.
I am trying to adapt this code to use CGI.pm, because it is more commonly available for CentOS 7
I'm not sure what your use case is here, but I strongly suspect that your time would be better spent working out how to install your required modules rather than working around the absence of certain modules.
If it helps you at all, I've just built an RPM of CGI::Simple and uploaded it to my RPM repository at rpm-mag-sol.com.
Upvotes: 4