I have attached a template with how to check the size of attachments.
It's approximate, so it will be off +/- 5% of actual size.
The textbox would be a hidden field.
You would want to add a validation to the textbox that makes sure the number is less than 500000 (may want to make it 550000, since the number is approximate)
See Attachment for how it works.