At 9:01 AM -0800 3/12/02, David Wheeler wrote:
>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.
Since when? I just wrote something that did just this (in CGI), but
it only uploaded the basename. I'm using Mac OS 9, IE 5.0. That
sounds a lot like IE 3.0.
The other way to go is
$filename = $1 if($filename =~ /[\:\/\\]([^\:\/\\]+)$/);
How many people use / : or \ in their paths? Can we shoot those
people? I especially don't want people who use those characters
uploading files that might be downloaded by someone on another
platform. Just think what would happen if I downloaded Foo:Bar.txt,
as uploaded by my windows friends.
Rob
--
When I used a Mac, they laughed because I had no command prompt. When
I used Linux, they laughed because I had no GUI.