function to remove the large amount of duplicated code.
Attach a file by drag & drop or click to upload