[Zope] Upload a file to the file system
Dieter Maurer
dieter@handshake.de
Mon, 27 Aug 2001 21:11:16 +0200 (CEST)
Gilles Lenfant writes:
> I'm trying to upload a file to the file system (using an external method).
> I got a :
>
> <form action="uploadfs" method="post" enctype="multipart/form-data">
> ....
> <input type="file" name="file">
> ....
> <input type="submit" value=" Upload "></form>
Already quite good.
def uploadfs(file):
open(file.filename,"wb").write(file.read())
return 'uploaded'
ATTENTION:
You *WILL* want to add checks that the client defined
"filename" can not overwrite arbitrary files on the
server.
Thus, in the production version, you will replace
the "file.filename" above with something more intelligent
and safer. You probably will only take the last component,
prepend a standard prefix
and add something to make the resulting name unique.
More enhancements expected....
Dieter