Setting a Limit to the Maximum Size of an Upload
Joey C.
joeyjwc at gmail.com
Thu Oct 27 05:52:05 EDT 2005
Yes, I see that now. I tried your method and it seemed to work fine
until I tried printing the filesize out.
def checkfilesize(thefile):
# Check the Size of the File
global filesize
thefile.seek(0,2)
filesize = thefile.tell()
thefile.seek(0)
print filesize
print conf["upmax"]
if filesize <= conf["upmax"]:
print "File Size Okay."
noupload = False
else:
print "File is too Large."
noupload = True
Basically conf["upmax"] is a number that I extract from a configuration
file that is the maximum size of an upload. I had tried setting
conf["upmax"] to 1 and it should have technically disallowed a 28 byte
file to pass through. But it did, so I added two lines to print the
file size and the conf["upmax"] variable.
The file size turned out to be "0"!
thefile still is just params["upfile"].file, by the way.
Any suggestions?
More information about the Python-list
mailing list