help with python cgi?

ttaco

New member
does anybody know whats wrong with this script?

#!C:\Python26
import cgi
import os
def template():
print 'content-type: text/html; charset=iso-8859-1\n\r'
print '<html>'
print '<head>'
print '</head>'
print '<body>'
print '<form action="" method="post">'
print '<input type="file" name="file">'
print '<input type="submit" value="upload">'
print '</form>'
print '</body>'
print '</html>'

def upload(f, upload_dir='C:\site'):
form=cgi.FieldStorage()
if not form.has_key(f):
return 0
fileitem=form[f]
if not fileitem.file:
return 0
fout=open(os.path.join(upload_dir, fileitem.filename), 'w')
while 1:
data=fileitem.file.read(1000)
if not data:
break
fout.write(data)
fout.close()

template()
upload('file')
 
Back
Top