[Zope] Export file attachment to actual filesystem
Daniel Tang
daniel.tang@chronicle.com
Mon, 12 May 2003 11:11:26 -0400 (EDT)
Hello,
I've tried numerous ways to try to export a file attachment to a temp
directory in the actual filesystem, but have failed to do so. Does anyone
know a way to do this?
I can export the file to the zope file system, but I would like to export
it to an actual directory outside of zope (e.g. /home/user/files/).
Thanks for anyone who has insight on this.
html page:
<FORM ACTION="mypage" METHOD="POST" ENCTYPE="multipart/form-data">
<INPUT TYPE="file" NAME="attach" VALUE="">
python code:
import string
import re
import time
form=context.REQUEST.form
REQUEST=context.REQUEST
if (form['attach'].filename != ''):
mimename = form['attach'].filename
mimearray = mimename.split(".")
if (len(mimearray) > 1):
mimetype = mimearray[-1]
else:
mimetype = "txt"
filename = "f" + str(ad_id) + "." + mimetype
new_id = "old_" + str(ad_id)
content_type=form['attach'].headers['Content-Type']
if content_type.find('image') != -1: #.find() is a method in Python2.0<
if hasattr(context.upload, filename):
context.upload.manage_delObjects(filename)
context.upload.manage_addImage(filename, form['attach'], filename)
else:
context.upload.manage_addImage(filename, form['attach'], filename)
else:
if hasattr(context.upload, filename):
context.upload.manage_delObjects(filename)
context.upload.manage_addFile(filename, form['attach'], filename)
else:
context.upload.manage_addFile(filename, form['attach'], filename)
--Daniel