upload file via form

Glenn S. java at dejazzd.com
Tue Dec 4 12:57:55 EST 2001


See my notation in your cgi code below, marked -->

That'll stuff the file into the response back to the browser.  If you
want to do things like properly handle images, etc., you need to do a
bit more.


Iddo Friedberg <idoerg at cc.huji.ac.il> wrote in message news:<Pine.GSO.4.40_heb2.09.0112040921370.5804-100000 at new-shum>...
> Hi,
> 
> This seems like a FAQ, but looking at the newsgroups, manuals etc. I could
> not find a reference to this.
> 
> I am trying to load a file to the server via a form.
>
> #!/usr/local/bin/python
> import cgi
> 
> form = cgi.FieldStorage()
> if form['userfile'].file:
>  contents = form['userfile'].file.value

-->contents = form['userfile'].value

> else:
>  contents = "Nothing here!"
> 
> print "Content-type: text/html"
> print
> print "<pre>"
> print contents
> print "</pre>"



More information about the Python-list mailing list