CGI upload

  • Thread starter Thomas Williams
  • Start date
T

Thomas Williams

Can anyone tell me where to find info, on writing a
script that handles a file from a CGI form?

Thanks in advance.

Tom Williams
 
G

Georgy Pruss

It uploads only a part of the file. Is it a feature of Windows implementation?

<!-- The form-->
<FORM METHOD="POST" ACTION="/cgi-bin/test.py" enctype="multipart/form-data">
<INPUT TYPE=FILE NAME="filename" size=40>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>


# test.py

print "Content type: text/html"
print

import cgi

form=cgi.FieldStorage()
if form.has_key("filename"):
filedata=form.getvalue("filename", "")
assert filedata == form["filename"].value # the same

print len(filedata), '<br>' # some 400..800 bytes depending on file :-(

fstrm = open("test.bin", 'wb')
fstrm.write(filedata)
fstrm.close()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top