#! /usr/local/bin/python
import cgi, tempfile
LOGFILE = "/usr/tmp/images.log"
Response = """
Image saved as
%(savefile)s
Email = %(email)s
Image = %(image)s
"""
Error = """ Error: email and image must be
specified
Email = %(email)s
Image = %(image)s
"""
def main():
form = cgi.FieldStorage() email = image = imagedata = None if
form.has_key("email"):
email = form["email"].value if
form.has_key("image"):
item = form["image"] if item.filename:
image = item.filename imagedata = item.value if email and
image:
savefile = tempfile.mktemp() f = open(savefile, "wb")
f.write(imagedata) f.close() logf = open(LOGFILE,
"a") logf.write("%s: %s\n" % (`email`,
`savefile`)) logf.close() print Response % locals() else:
print Error % locals()
try:
print "Content-type: text/html\n\n" main() except:
cgi.print_exception()
# Here's a possible form for this script:
# Invitation
#