[mod_python] uploaded file names

Daniel J. Popowich dpopowich at mtrsd.k12.ma.us
Thu Jun 3 12:03:44 EDT 2004


This is not really a mod_python question, but I figure a number of you
have had to deal with this.

On a windows client, let's say we have a file named:

  c:\foo\bar\baz

which is what a user specifies in an HTML INPUT file widget.

If the client is a mozilla browser the file name is returned as the
basename of whatever was specified, so 'baz'.  If the client is IE the
file name is returned as the full path name specified, so
r'c:\foo\bar\baz'.  Leave it to M$ to complicate matters.

This means I need to code my handler to expect either a basename or a
full pathname.  All I want is the basename.  Complicating the matter
is my handler is on a linux box, so my server-side python is compiled
to handle unix paths, not windows paths (so I can't use functions like
os.path.splitdrive).

My solution, which I fear may be braindead, is to do this to all
incoming filenames:

  filename = os.path.basename(filename.replace('\\', '/'))

This appears to work, but I'm wondering if anyone else has a better
solution.

Thanks,

Daniel



More information about the Mod_python mailing list