Valkerri has asked for the wisdom of the Perl Monks concerning the following question:

I am receiving files from an HTML form using:

<input TYPE="file" NAME="attachedfile" MAXLENGTH=50 ALLOW="text/*">

Then, I email the attachments using MIME::Lite. I used (regardless of file type received):

$message -> attach (Path => $pathtofile, Type => 'binary');

I tested this from my Mac in both Netscape and IE. The results were very reliable this way. None of the files were corrupted and the filenames were readable.

Testing from a Windows machine, however, resulted in filenames being the whole path from the person's computer.

Is there something I am missing or do I have to fix the filename myself?

Thanks in advance for your help.

Replies are listed 'Best First'.
Re: Paths for filenames from Windows with TYPE=file
by grinder (Bishop) on Jun 27, 2001 at 19:46 UTC

    Personally I would tend to want to throw away the original filename as fast as possible, but I don't know the specifics of your application.

    If you want to strip out the path from the canonical name the following will do the trick:

    use File::Basename; # it's in the core distribution $canonical =~ tr{\\}{/}; # if the path separator is \ and not / my $filename = basename( $canonical );

    Note that you may have to fiddle mapping \ to / to get File::Basename to work correctly on Unix platforms.


    --
    g r i n d e r

      I thought File::Basename was a portable way of getting the basename from a local path, i.e., it takes care of your platform's oddities for you.

      But in that case, the filename you get is the full path on the user's machine, and I don't think File::Basename can determine what OS it is running and what a path separator looks like there.

      So your first advice seems the best to me: throw away the filename!

      --bwana147