upload file via form

Iddo Friedberg idoerg at cc.huji.ac.il
Tue Dec 4 02:24:33 EST 2001


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. Here's the form:

<html>
<head>
<title> Try This</title>
</head>
<body>
<FORM ACTION="/cgi-pc/upload.py" method=POST>
<p>Upload a file!</p>
<INPUT TYPE="file" name="userfile" SIZE="30">
<INPUT TYPE=SUBMIT value=SEND!>
</FORM>

And here's the CGI script which is supposed to read and display the
contents:

#!/usr/local/bin/python
import cgi

form = cgi.FieldStorage()
if form['userfile'].file:
	contents = form['userfile'].file.value
else:
	contents = "Nothing here!"

print "Content-type: text/html"
print
print "<pre>"
print contents
print "</pre>"

I always get a "Nothing here!" What am I doing wrong?

I'm using an Apache1.3, on Linux RH7.1.


Yours,

Iddo

-- 

Iddo Friedberg                                  | Tel: +972-2-6758647
Dept. of Molecular Genetics and Biotechnology   | Fax: +972-2-6784010
The Hebrew University - Hadassah Medical School | email: idoerg at cc.huji.ac.il
POB 12272, Jerusalem 91120                      |
Israel                                          |
http://bioinfo.md.huji.ac.il/marg/people-home/iddo/




More information about the Python-list mailing list