[Zope] file upload question
Phil Harris
phil@philh.org
Fri, 9 Jul 1999 15:35:52 +0100
Try something like this,
upload_html:
<FORM ACTION="upload_external" METHOD="POST"
ENCTYPE="multipart/form-data">
<TABLE CELLSPACING="2">
<TR>
<TH ALIGN="LEFT" VALIGN="TOP">File</TH>
<TD ALIGN="LEFT" VALIGN="TOP">
<INPUT TYPE="file" NAME="file" SIZE="25" VALUE="">
</TD>
</TR>
<TR>
<TD></TD>
<TD><BR><INPUT TYPE="SUBMIT" VALUE="Change"></TD>
</TR>
</TABLE>
</FORM>
external method called upload_external:
import os, shutil
def upload_external(self,file,REQUEST):
#check if file was sent correctly
if file.read(1) == '':
return '<h2>File does not exist</h2>'
else:
file.seek(0)
iname=os.path.basename(file.filename)
oname=os.path.join(self.savedir,iname)
f=open(oname,"wb")
f.write(file.read())
# let's get the mime information
mime_type=file.headers.headers[1]
user=str(REQUEST.AUTHENTICATED_USER)
try:
self.add_entry(path=self.savedir,filename=iname,owner=user)
except:
os.remove(oname)
return '<h2>File upload not completed correctly</h2>'
return '''<h2>%s was sent correctly, and saved in %s</h2><h3>The Mime Type
of the file is</h3>%s<h3>Saved by</h3>%s''' % (iname,oname,mime_type,user)
The self.savedir is a property set in the folder which contains the external
method and tells the external method where to put the file.
The self.add_entry is an update on a database to keep track of the files
uploaded, etc.
The rest should be self explanatory, ;)
HTH
Phil
phil@philh.org
----- Original Message -----
From: <michael@garage.co.jp>
To: <zope@zope.org>
Sent: Thursday, July 08, 1999 6:23 AM
Subject: [Zope] file upload question
> Hi all
>
> I would like to write a dtml script that will upload files to a
> specific directory, not to Zope (or as an Zope object). Can anyone
> please give me some pointers.
>
> Help appreciate.
>
> Thanks.
>
> Michael
>
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://www.zope.org/mailman/listinfo/zope
>
> (For developer-specific issues, use the companion list,
> zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
>