By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,766 Members | 1,393 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,766 IT Pros & Developers. It's quick & easy.

check uploaded file's file size?

P: n/a
i have a short script that allows users to upload files, but when i try
to check for a valid filesize (using fileitem) i get '-1' i can't find
information about using filesize anywhere. any ideas?

code:

form = cgi.FieldStorage()
fileitem = form["datafile"]
print str(fileitem.filesize)

-h3m4n

Jul 8 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
h3m4n wrote:
i have a short script that allows users to upload files, but when i try
to check for a valid filesize (using fileitem) i get '-1' i can't find
information about using filesize anywhere. any ideas?

code:

form = cgi.FieldStorage()
fileitem = form["datafile"]
print str(fileitem.filesize)

-h3m4n
Try this

fileitem.seek(0, 2) # Seek to the end of the file.
filesize = fileitem.tell() # Get the position of EOF.
fileitem.seek(0) # Reset the file position to the beginning.

If the fileitem is a normal file this should work.
Peace,
~Simon

Jul 8 '06 #2

P: n/a
Try this
>
fileitem.seek(0, 2) # Seek to the end of the file.
filesize = fileitem.tell() # Get the position of EOF.
fileitem.seek(0) # Reset the file position to the beginning.
thanks for the info. i just had to change it from fileitem to
fileitem.file, e.g. fileitem.file.seek(0, 2), and it worked fine.

- h3m4n
Jul 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.