check uploaded file's file size?

H

h3m4n

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
 
S

Simon Forman

h3m4n said:
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
 
H

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top