check file size at the client side

To check the size of a file (before form submission), you can do it easily as follows:

function validate_file(){

	file_obj = document.getElementById('my_file').files[0];
	if (typeof file_obj != 'undefined'){
		if (file_obj.size > 2000000){  // 2Mb
			alert('file size is greater than 2Mb');
			return false;
		}
	}
			
	return true;
}

If you really want to do something fancy, check out this site:
http://www.html5rocks.com/en/tutorials/file/dndfiles/#toc-reading-files

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s