What did you learn when you tried a few of the more obvious searches
with Google (including the word "python" in the search)? You must have
learned _something_ but still have questions, so please tell us what you
already know so we can skip over the easy stuff.
Knowing what you've already discovered will avoid having everyone here
repeat all the same answers (which you can easily find in the Google
Groups archives) to what is a fairly common sort of question.
-Peter
Very well then. I did search google, and found a number of python scripts
that already do the job (more or less). But when I try to tweak them to my
specifications, I get errors ... probably because I don't really
understand how the process of uploading a file via a webform to a cgi
works.
For e.g, take the script at this url.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/273844
By reading through this script, I know that simply putting '<input
name="file_1" type="file">' in your web form will establish a connection
to the cgi when the client submits the form. The python interpreter
obviously sustains that connection while the file is being transferred,
the file being part of the FieldStorage() instance. But then, the script
saves the file to the disk in some special way I don't understand. In this
case:
fout = file (os.path.join(upload_dir, fileitem.filename), 'wb') while
1:
chunk = fileitem.file.read(100000)
if not chunk: break
fout.write (chunk)
fout.close()
chunk = fileitem.file.read(100000), and fout.write (chunk) seem to be the
key statements. Could someone elaborate on these for me please? And why
do they need to be in a while loop?