os.path.basename() - only Windows OR *nix?

Larry Bates lbates at websafe.com
Wed Mar 14 20:27:10 CET 2007

Thomas Ploch wrote:
> Steve Holden schrieb:
>> Clearly if form['uploadfile'] is returning the client's path information 
>> you do have to remove that somehow before further processing, which also 
>> means you need to deduce what the client architecture is to correctly 
>> remove path data. Of course this also leaves open the question "what 
>> does a Mac client return?", and you might want to cater for that also.
> I tested from linux and Mac OS, and on both os.path.basename() works as
> expected (since the server it runs on is a UNIX one). That brings me to
> the question, how Do I a) get the cients architecture and b) send the
> architecture of the client through cgi.FieldStorage()?
>> I suspect you will also find that there are at least some circumstances 
>> under which a Unix browser will also include path information.
> Which ones should that be? Since os.path.basename() _is_ doing the right
> thing on *nix style paths (Mac OS is not different there), I cant think
> of other circumstances.
>> I presume you are looking to use the same filename that the user 
>> provided on the client? Does this mean that each user's files are 
>> stored in different directories? Otherwise it's not always a good idea 
>> to use filenames provided by the user for files on the server anyway.
> Yes, each User has his own directory. Files get timestamped and then put
> into the corresponding directory. It is just that having
> 'C:\a\very\long\path\file.ext' as a filename on the server is not nice.
> Thomas

You will need to write some Javascript and assign something to a hidden
field that gets posted.  Here is some Javascript to get you started:



More information about the Python-list mailing list