Update upload.php

Compressed filename generator into for loop, now check DB to see if file exists vs checking file system. Untested.