Skip Menu |

This queue is for tickets about the CGI-Upload CPAN distribution.

Report information
The Basics
Id: 5278
Status: new
Priority: 0/
Queue: CGI-Upload

People
Owner: Nobody in particular
Requestors: MARKSTOS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.05
Fixed in: (no value)



Subject: wish: file extension support
Hello, I'd like it if this module could also figure an appropriate file extension. Here's some code borrowed from Data::FormValidator::Constraints::Upload that does that. It tries to make a 'smart' decision based on the file type that was uploaded, and possible "MIME::Type' alternatives: # figure out an extension use MIME::Types; my $mimetypes = MIME::Types->new; my MIME::Type $t = $mimetypes->type($mt); my @mt_exts = $t->extensions; my ($uploaded_ext) = ($img =~ m/\.([\w\d]*)?$/); my $ext; if (scalar @mt_exts) { # If the upload extension is one recognized by MIME::Type, use it. if (grep {/^$uploaded_ext$/} @mt_exts) { $ext = $uploaded_ext; } # otherwise, use one from MIME::Type, just to be safe else { $ext = $mt_exts[0]; } } else { # If is a provided extension but no MIME::Type extension, use that. # It's possible that there no extension uploaded or found) $ext = $uploaded_ext; }