I'd suggest try the change event? test to see if it has a value if it does then you can continue with your code. jQuery has
.bind("change", function(){ ... });
Or
.change(function(){ ... });
which are equivalents.
for a unique selector change your name attribute to id and then jQuery("#imafile")
or a general jQuery('input[type="file"]')
for all the file inputs