[Zope] Obtaining just the filename for multiple file fields in an add form form

Darin Lee leedm@state.mi.us
Fri, 03 Nov 2000 14:14:03 -0500


Zopistas,

I have a form that has multiple file upload fields in it (5 to be exact). I am handling the upload via DTML. Essentially this is a "publication" item that can have multiple formats of a file attached (PDF,  Powerpoint, Word, Excel, HTML). I would like the user to create the publication item (Zclass object), and then attach whatever format files they require to the add form.

The Publication object is folderish and contains which of the files they uploaded. The problem comes in with naming the files. I can't figure a way to get the file name from the upload field without getting the entire local path on the user's machine.


The following code works, if I manually delete the path out of the field in the browser (ie5) and just leave the filename:
<dtml-call "manage_addFile(_.getattr(file1, 'filename'), REQUEST['file1'])">  

However, I would rather get the filename, split it on the \'s, and then take a slice to get at the actual filename [:1] to pass to manage_addFile. The problem is, I'm not sure how to get this to work in DTML.

This is also clumsy, because in this case there are 5 file upload fields on the form - the way I am approaching it would require the same code to be repeated 5 different times. Is there an array/list of the file fields I could loop through?

Thanks in advance,
-Darin Lee