On Tue, 2002-03-12 at 03:57, Rich Bowen wrote:

> my $form = Your::Class::form(); # Wherever you put this function
> if (my $file = $form->{UPLOAD}) {
>     my $filename = $file->filename; # If you need the name

Actually, if you want the name, it's a really good idea to just get the
basename, since some browsers on some platforms (e.g., IE/Mac) send the
complete path name to the file on the browser's local file system (e.g.,
':Mac:Foo:Bar:image.jpg'). This is trickier than it sounds, because you
have to tell basename() what platform to assume the file is from. Here's
how I suggest doing it.

    use File::Basename;
    use HTTP::BrowserDetect;

    my $browser = HTTP::BrowserDetect->new($ENV{HTTP_USER_AGENT});

    # Tell File::Basename what platform to expect.
    fileparse_set_fstype($browser->mac ? 'MacOS' :
                         $browser->windows ? 'MSWin32' :
                         $browser->dos ? 'MSDOS' :
                         $browser->vms ? 'VMS'
                         $browser->amiga ? 'AmigaOS' :
                         $^O);

    # Get the file name.
    my $filename = basename($file->filename);

    # Be sure to set File::Basename to the local file system again.
    fileparse_set_fstype($^O);

HTH,

David

-- 
David Wheeler                                     AIM: dwTheory
[EMAIL PROTECTED]                                 ICQ: 15726394
http://david.wheeler.net/                      Yahoo!: dew7e
                                               Jabber: [EMAIL PROTECTED]

Reply via email to