Before upload, impossible. Javascript is definitely not capable of doing this (with ActiveX, maybe, but that'd only work on old versions of IE).
But these classes could help:
http://www.phpclasses.org/browse/package/4395.html
http://www.phpclasses.org/browse/package/1042.html
(Haven't tested them)