[mod_python] uploaded file names

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


Nick writes:
> Daniel J. Popowich wrote:
> 
> > My solution, which I fear may be braindead, is to do this to all
> > incoming filenames:
> > 
> >   filename = os.path.basename(filename.replace('\\', '/'))
> 
> You may want to test the user agent first for IE before replacing the \ 
> wholesale

Good point.

> but in general I don't think people put backslashes in filenames.

But you can't count on that and if the user uses the browse button to
find the file, then the path WILL have backslashes.

>     Personally, I do:
> 
> try:
>      filename[filename.rindex('\\') + 1:]
> except ValueError:
>      pass

Thanks,

Dan



More information about the Mod_python mailing list