uploaddir /uploadstrue=read file at once dir to store files sys stderr sys stdout form cgi fieldstorage(print("content-typetext/html\ "if debugmodecgi print_form(formshow error msgs parse form data with blank line print form fields html templates html ""putfile response page putfile response page % ""goodhtml html ""your file'% 'has been saved on the server as '%san echo of the file' contents received and saved appears below % ""process form data def splitpath(origpath)for pathmodule in [posixpathntpathmacpath]basename pathmodule split(origpath)[ if basename !origpathreturn basename return origpath get file at end try all clients may be any server lets spaces pass failed or no dirs def saveonserver(fileinfo)use file input form data basename splitpath(fileinfo filenamename without dir path srvrname os path join(uploaddirbasenamestore in dir if set srvrfile open(srvrname'wb'always write bytes here if loadtextautofiletext fileinfo value reads text into string if isinstance(filetextstr)python hack filedata filetext encode(srvrfile write(filedatasave in server file elseelse read line by line numlinesfiletext ' for huge files while truecontent always str here line fileinfo file readline(or for loop and iterator if not linebreak if isinstance(linestr)python hack line line encode(srvrfile write(linefiletext +line decode(ditto numlines + filetext ('[lines=% ]\nnumlinesfiletext srvrfile close( server-side scripting