File Upload in cgi
Sim & Golda Zacks
simngolda at voyager.net
Thu Jul 15 00:21:52 EDT 1999
Code posted below
I am trying to upload a file to my cgi-script and I seem to be failing
miserably. In my html page the item is of input type file and I select a
file and hit submit and when I access it with the FieldStorage() and
then print it it says it's not a file. I am basically copyng the example
in the cgi module documentation. it prints out
MiniFieldStorage('picture',
'C:\\TEMP\\WebPage\\baby3.gif')
and then it prints not a file. The file isn't on the server either. Can
someone tell me what I'm doing wrong?
import cgi
def main():
print "Content-type: text/html"
print
print "Testing what happens for a picture"
form=cgi.FieldStorage()
pic=form["picture"]
print pic
if pic.file:
l=pic.file.readlines()
g=open('newpic.gif','wb')
g.writelines(l)
g.close()
print 'wrote file'
else:
print 'not a file'
if __name__=="__main__":
main()
More information about the Python-list
mailing list