Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve the size of a file before uploading it?

I have an file input tag in my web app. I'd like to check that the file isn't too big before sending it to the server. Of course, I still have validation server side. Is there any way to do this with JavaScript? It must work in IE7+ and FF3+. Thank you.

EDIT: somefileinputobject.files[0].filesize works in FF, but not IE.

like image 585
geowa4 Avatar asked Feb 13 '09 19:02

geowa4


1 Answers

It's a hard problem. You have to do it with AJAX, and use the filesize headers sent by the browser to the server on the POST request.

Yahoo's UI Library has a tool to help with this. YUI Uploader

like image 92
Jeremy DeGroot Avatar answered Oct 07 '22 15:10

Jeremy DeGroot