dealing with paths, multiple OS versions, cgi's

Glenn Stauffer python at dejazzd.com
Mon Mar 18 14:26:33 EST 2002


I have a cgi program that accepts an uploaded file through a web form and 
then attaches that file to an email message.  I've run into a problem in 
testing that I haven't yet found a solution for and am hoping that someone 
could steer me in the right direction.

When a file is uploaded through certain browsers - like the AOL web browser - 
the form['file'].filename value is a path.

>From a Windows browser, the path will be something like 
c:\temp\file.doc

>From a Unix browser, it might be: /home/user/file.doc

Now, the CGI runs on a linux server, so os.path.basename() will return the 
base filename for the files being uploaded from a unix browser, but they will 
not properly handle the files being uploaded from a Windows browser.

What I need is some method for stripping off the basename regardless of the 
browser OS.

Any ideas?

Thanks, Glenn




More information about the Python-list mailing list