I added the code as you suggested, but the next two submissions seemed to go through. The problem has been very sporadic.
One thing I have noticed is the file upload folder on the server contains a lot of files with long hex filenames such as dbfcb832aa15b2efb4b35260dd1f9bcf_tmp.JPG. The latest few seemed to coincide with the times the form has failed. This makes me think many people are having the form failure and not notifying me.