According to the Illinois Department of Public Health, all flies are attracted to moist organic material, including dead animals, rotting vegetables and fruits and scraps of meat. When flies land in garbage, they feed and lay their eggs, and they also regurgitate the contents of their stomachs, which can contaminate food and food surfaces.
Fly infestations can be prevented by keeping all surfaces areas clean of materials they are attracted to. Dumpsters should be emptied and kept as clean as possible by placing trash in trash bags. Garbage cans should have tight-fitting lids, and areas of excessive moisture need to be eliminated.