fixed loop for uploading files