Hey, Folks:
I'm trying to write a very simple file upload CGI. I'm on a Windows server.
I *am* using the -u switch to start Python for CGIs, as follows:
c:\python\pytho n.exe -u %s %s
I *do* have write permissions on the directory I'm trying to write to. But,
when I click submit, it just hangs. Any help would be greatly appreciated.
Thanks. Here's the code...
Upload.py
import cgi
print "content-type: text/html\n\n"
form = cgi.FieldStorag e()
if not form:
print """
<html>
<head></head>
<body>
<form name="frmMain" action="Upload. py" method="POST"
enctype="multip art/form-data">
<input type="file" name="filename" ><br>
<input type="submit">
</form>
</body>
</html>
"""
else:
import BLOB
lobjUp = BLOB.BLOB()
if lobjUp.Save('fi lename', 'SomeFile.jpg') :
print """
<html>
<head></head>
<body>
File successfully saved.
</body>
</html>
"""
else:
print """
<html>
<head></head>
<body>
Unable to save file.
</body>
</html>
"""
--------------
Blob.py
import cgi
import staticobject
cTrue = 1
cFalse = 0
try:
import msvcrt,os
msvcrt.setmode( 0, os.O_BINARY ) # stdin = 0
msvcrt.setmode( 1, os.O_BINARY ) # stdout = 1
except ImportError:
pass
class BLOB(staticobje ct.StaticObject ):
def __init__(self):
self.initializi ng = cTrue
staticobject.St aticObject.__in it__(self)
self.initializi ng = cFalse
def Save(self, pstrFormFieldNa me, pstrFilePathAnd Name):
# tried this first -- same result -- just hangs...
# try:
# form = cgi.FieldStorag e()
# item = form[pstrFormFieldNa me]
# if item.file:
# data = item.file.read( )
# f = open(pstrFilePa thAndName,'wb')
# f.write(data)
# f.close()
# return cTrue
# else:
# return cFalse
# except:
# return cFalse
form = cgi.FieldStorag e()
f = open(pstrFilePa thAndName,'wb')
f.write(form[pstrFormFieldNa me].value)
f.close()
I'm trying to write a very simple file upload CGI. I'm on a Windows server.
I *am* using the -u switch to start Python for CGIs, as follows:
c:\python\pytho n.exe -u %s %s
I *do* have write permissions on the directory I'm trying to write to. But,
when I click submit, it just hangs. Any help would be greatly appreciated.
Thanks. Here's the code...
Upload.py
import cgi
print "content-type: text/html\n\n"
form = cgi.FieldStorag e()
if not form:
print """
<html>
<head></head>
<body>
<form name="frmMain" action="Upload. py" method="POST"
enctype="multip art/form-data">
<input type="file" name="filename" ><br>
<input type="submit">
</form>
</body>
</html>
"""
else:
import BLOB
lobjUp = BLOB.BLOB()
if lobjUp.Save('fi lename', 'SomeFile.jpg') :
print """
<html>
<head></head>
<body>
File successfully saved.
</body>
</html>
"""
else:
print """
<html>
<head></head>
<body>
Unable to save file.
</body>
</html>
"""
--------------
Blob.py
import cgi
import staticobject
cTrue = 1
cFalse = 0
try:
import msvcrt,os
msvcrt.setmode( 0, os.O_BINARY ) # stdin = 0
msvcrt.setmode( 1, os.O_BINARY ) # stdout = 1
except ImportError:
pass
class BLOB(staticobje ct.StaticObject ):
def __init__(self):
self.initializi ng = cTrue
staticobject.St aticObject.__in it__(self)
self.initializi ng = cFalse
def Save(self, pstrFormFieldNa me, pstrFilePathAnd Name):
# tried this first -- same result -- just hangs...
# try:
# form = cgi.FieldStorag e()
# item = form[pstrFormFieldNa me]
# if item.file:
# data = item.file.read( )
# f = open(pstrFilePa thAndName,'wb')
# f.write(data)
# f.close()
# return cTrue
# else:
# return cFalse
# except:
# return cFalse
form = cgi.FieldStorag e()
f = open(pstrFilePa thAndName,'wb')
f.write(form[pstrFormFieldNa me].value)
f.close()
Comment